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

Condition runs even if it's true?

Asked by 2 years ago
-- i have a round system and i have a for loop nested in a while loop constantly
-- checking if a player died, then removing it from a table called "alive players".

-- even when i don't die, the output constantly prints that i died. The stranger thing is
-- it doesn't remove me from the table. Could someone help?

    while wait() do
        for i,e in pairs(workspace:GetChildren()) do
            if e:FindFirstChild("HumanoidRootPart") then
                if e.Humanoid.Died ~= nil then
                    table.remove(alivePeople,i)
                    print(tostring(e).." DIED")
                    print(#alivePeople)
                end
                if #alivePeople == 1 then
                    print(tostring(e).. " WON")
                    game:GetService("StarterGui").ScreenGui.TextLabel.Text = (e.Name.." Won!")
                    timer.Value = 3
                    break
                end
            end
        end 
    end
0
`Humanoid.Died` is an event, not a boolean value. TheeDeathCaster 2368 — 2y
0
since e.Humanoid.Died is an event, the event exists, therefore it's like saying "if e == true then", thus always being true greatneil80 2647 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

Instead of saying:

if e.Humanoid.Died ~= nil then 

Try this:

if e.Humanoid.Health <= 0 then

--Everything else

The reason that this is erroring is because you are trying to assign an Event to a bool value (true/false). You cant do that. So, we can check to see if the humanoids health (a numberValue) is less then 0 (because if it is under 0 then roblox kills the player automatically, so we know that they died.)

0
thanks for the help! rokkufera 6 — 2y
Ad

Answer this question