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

regular if statement not working?

Asked by 6 years ago

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!

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 Legoman654 100 — 6y

1 answer

Log in to vote
0
Answered by
Bazuxk 95
6 years ago
Edited 6 years ago

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

Ad

Answer this question