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

I am trying to make a kill function but it is not working can someone help me?

Asked by
tjtorin 172
7 years ago
function die(hit)
    if hit.Parent:FindFirstChild("Huminoid") then
        hit.Parent.Head:Destroy()
    end
end
die()

I am trying to make a function that kills the player when they touch the parent of this script but it keeps on saying: Workspace.Part.Script:2: attempt to index local 'hit' (a nil value)

0
Could it possibly be the fact you misspelt Humanoid? BunnyFilms1 297 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Use http://wiki.roblox.com/index.php?title=API:Class/BasePart/Touched

So:

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Huminoid") then
        hit.Parent.Head:Destroy()
    end
end)

So the issue you were having is that you were calling the function not only once, but with no arguments, you need to call it when something touches a part.

1
Another issue is, he's trying to find Huminoid M39a9am3R 3210 — 7y
0
And he should use FindFirstChildOfClass. Names can change. Programical 653 — 7y
Ad

Answer this question