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

Why does this simple kill script not work?

Asked by 10 years ago

Doesnt work... ._.

script.Parent.Touched:connect(function(hit)
    print(hit)
    hit.Parent.Humanoid.Health = 0
end)

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

This will work, but only as long as the touched never errors.

A lot of contacts, though, would cause this to error.

Always include robust error checking in your code.

script.Parent.Touched:connect(function(hit)
    print(hit)
    if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
        hit.Parent.Humanoid.Health = 0
    end
end)
0
Thanks My_Comment 95 — 10y
Ad

Answer this question