Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

1 comment

0

I learned so much from this! Thank you times a million. :)

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!

2 comments

0

You shouldn't place items you need to store into Lighting, there are reasons for Server Storage and Replicated Storage (including lag reduction)

1

I changed that thanks. I learned something from answering a question...

This discussion is preserved as it was. New answers, comments, and votes are closed.