Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

regular if statement not working?

So, I made an if statement that checks when you're dead. Since you don't need the full code, I'll just make one with the same scenario.

This is a Localscript, and this is filtering enabled!!

while wait(1) do
	if game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").Health == 0 then --my true problem
		warn("This is a test") --i prefer warn, as it is easier to see in the output.
	end
end

What is wrong? It seems normal, but the warn doesn't appear in the output!

1 comment

0

how is the player losing HP? I tested my self by setting the property value to 0 while in test mode and it works fine. If you're subtracting HP somewhere else, change your operator from == to <= as the math can leave decimals

1 answer

✓ Accepted answer

Instead of using loop, use the humanoid's event.

For example the Died() :

--localscript

local Plr = game.Players.LocalPlayer

Plr.Character.Humanoid.Died:Connect(function()
	print('player dies')
end)

What it does is triggering the function as soon as the player's health hits zero.

For more information related to this : http://wiki.roblox.com/index.php?title=API:Class/Humanoid

This discussion is preserved as it was. New answers, comments, and votes are closed.