I have made this script that is designed to hurt non-player humanoids, however it does not work. What am I doing wrong here?
function enemy(hit)
local h = hit.Parent:findFirstChild("Humanoid")
local name = h.Parent
local player = game.Players.FindFirstChild(name)
if h ~= nil then
if name ~= player then
h.Health = h.Health - 100
end
end
end
script.Parent.Touched:connect(enemy)
When I use the script I get these errors, the first one I think is supposed to happen but I really don't know what to make of the second.
21:17:00.905 - Workspace.Player.Tool.arrow.Script:4: attempt to index local 'h' (a nil value)
21:17:00.906 - Stack Begin
21:17:00.907 - Script 'Workspace.Player.Tool.arrow.Script', Line 4
21:17:00.908 - Stack End
21:17:00.985 - Argument 1 missing or nil
21:17:00.986 - Script 'Workspace.Player.Tool.arrow.Script', Line 5
21:17:00.987 - Stack End

3 comments
can't believe I overlooked that, lol. Thanks a ton
I appreciate that little extra mile you went to keep the script from breaking, without i'd of probably ended up making a new thread about fixing it.
xD no problem :)