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

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

Asked by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

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

Log in to vote
2
Answered by 8 years ago

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.

Ad

Answer this question