Attempt to index nil with health, but it still works?

I have a script and i keep getting the error "Attempt to index nil with nil with ‘Health’ ", However the code that I am using still works without issue (besides the error), and I know that its this script specifically, because when I deleted the code, nothing happened. I have pasted the code below,.

-- server script inside a tool
script.Parent.RemoteEvent.OnServerEvent:Connect(function(Player, hithum)
	if hithum == Player.Character.Humanoid then
	else
		hithum.Health -= 7
	end
end)

You could perhaps add this little check:

script.Parent.RemoteEvent.OnServerEvent:Connect(function(Player, hithum)
	if hithum == Player.Character.Humanoid then
	elseif hithum ~= nil and hithum.ClassName == "Humanoid" then
		hithum.Health -= 7
	end
end)
1 Like

That Worked! Thank you! I didnt expect anyone to reply so fast lol.

1 Like

Can you mark my comment as the solution?:sweat_smile: Thanks anyway!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.