I'm trying to spawn in a brick that will kill the player when touched. Here is my best effort so far! Any help would be incredible.
part = Instance.new("Part") part.Position = Vector3.new(275.08,0.5,-295.075) part.Anchored = true part.Parent = game.Workspace.Tsunami part.BrickColor = BrickColor.Blue() part.Size = Vector3.new(205.89,1,79.77) part.TopSurface = 0 if 2+2==4 then do Parent.Touched:connect(function(part) if part.Parent:FindFirstChild("Humanoid") then part.Parent.Humanoid.Health = 0 (wait(.5) end`
GENERAL PRACTICE
Use workspace
instead of game.Workspace
Use :WaitForChild()
to make sure a part exists before changing it.
You do not need the "2 + 2 == 4" section of your code to allow the connection to operate
ISSUES
"Parent" is not a defined variable
The property of TopSurface is an Enum not a number
You previously defined "part" as a new instance, when the parameter of .Touched()
is the part that touched "part"
connect
is deprecated in favor of Connect
REVISED SERVER SCRIPT
local part = Instance.new("Part") part.Position = Vector3.new(275.08, 0.5, -295.075) part.Size = Vector3.new(205.89, 1, 79.77) part.Anchored = true part.BrickColor = BrickColor.Blue() part.TopSurface = Enum.SurfaceType.Smooth part.Parent = workspace:WaitForChild("Tsunami") part.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then hit.Parent:WaitForChild("Humanoid").Health = 0 wait(.5) end end)
You could make the killbrick with the kill script in it then put it into ServerStorage(Not Lighting), then change it's parent to Workspace. Or, you could make the script that would go into the block, then copy it into the new kill part. I hope that this helps!