I'm learning LUA and trying to make a GUI that spawns a brick above the players head which kills the player if touched. I'm not sure how to to connect the Touched event to a part that's spawned in with Instance.new? Here's what I got so far!
local button = script.Parent
local function kill()
button.BackgroundColor3 = Color3.fromRGB(255, 0, 4)
button.parent.BackgroundColor3 = Color3.fromRGB(255, 0, 4)
local player = game.Players.LocalPlayer.character
local killBrick = Instance.new("Part")
killBrick.Name = "Kill Brick"
killBrick.CFrame = player.Head.CFrame*CFrame.new(0,10,0)
killBrick.Parent = game.Workspace
killBrick.Color = Color3.fromRGB(255, 0, 0)
killBrick.Material = "Neon"
killBrick.BottomSurface = "Smooth"
killBrick.TopSurface = "Studs"
button.BackgroundColor3 = Color3.fromRGB(80, 80, 255)
button.parent.BackgroundColor3 = Color3.fromRGB(106, 146, 255)
end
button.MouseButton1Click:Connect(kill)