I'm creating a Death Brick script and i tried many ways but i always get an index error.
Script:
function onTouch(hit)
Player = game.Players:getPlayerFromCharacter(hit.Parent)
h = Player:findFirstChild("Humanoid")
if h then
h.Health = 0
--print(("The noob %s died"):format(h.Parent.Name)) //Only enable if you're willing to have a spammed console.
end
end
script.Parent.Touched:connect(onTouch)
Error: attempt to index global 'player' (a nil value)

3 comments
The print was put on there for fun :P.
It no longer kills the player. Why is that?
NEVERMIND, I figured that out.