Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you spawn in a brick that kills when touched?

Asked by
gobrett 11
5 years ago
Edited 5 years ago

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`

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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)
0
I learned so much from this! Thank you times a million. :) gobrett 11 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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!

0
You shouldn't place items you need to store into Lighting, there are reasons for Server Storage and Replicated Storage (including lag reduction) SerpentineKing 3885 — 5y
1
I changed that thanks. I learned something from answering a question... User#26817 0 — 5y

Answer this question