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

How to create a basic script which kills the player when a specific part is touched?

This is a really simple thing but I need help. I've no example this time, but I need to know if it goes in a LocalScript or Script, its parent, and what's contained in the script.

1 answer

✓ Accepted answer

If you had provided an example, this would be a lot easier to answer. Have you tried anything yet?

Anyway, here goes nothing.

I haven't tried LocalScripts before for a kill brick, so I'd just say to keep it a script.

I'd write a connection line first.

script.Parent.Touched:connect(function(hit)

Your function doesn't have to be named hit, but it's convenient.

So, then you need to find the humanoid. The following would be incorrect:

local humanoid = hit:FindFirstChild("Humanoid")

Because no part of your character will include a humanoid. Therefore, you need to check the parent.

local humanoid = hit.Parent:FindFirstChild("Humanoid")

then you can set the health to 0 like such:

humanoid.Health = 0

That leaves the script as this:

script.Parent.Touched:connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
humanoid.Health = 0
end)

I hope this answered your question sufficiently.

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