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

My AliveChecker that consists of conditionals and loops isn't working, help?

Asked by
Mr_Unlucky 1085 Moderation Voter
5 years ago
Edited 5 years ago

What I'm trying to do is that for every single player it's going to run through a series of checks, and if they are dead or they left the game they are counted as not alive and then they are removed from a table.

for x,v in pairs(plrs) do
    if v then
        local Character = v.Character
        if not Character then
            table.remove(AlivePlayers,x)
        else
            if Character:FindFirstChild("Alive").Value then
                print(Character.Name.." is still alive.")
            else
                table.remove(AlivePlayers,x)
            end
        end
    else
        table.remove(AlivePlayers,x)
    end
end

0
you don't need to advertise this through chat WideSteal321 773 — 5y
0
ik but it hasnt gotten any exposure for 2 hours Mr_Unlucky 1085 — 5y

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago

I believe, I may not be correct, go easy... But I believe your issue lies on line 07 your if statement hasn't specified exactly what you're hoping 'Alive' is to equal, sometimes silent outputs consist of synax related problems, honestly if this statement was to run, It wouldn't matter what it equals, as long as Alive is equal to what it is, go through with it. So I suggest writing it like so

01
for Placement,Players in ipairs(plrs) do
    if v them
        local Character = Player.Character or Player.CharacterAdded:wait() --// more efficient
        if not Character then
            table.remove(AlivePlayers,Placement)
        else
            if Character:FindFirstChild("Alive").Value ~= false then
                print("'"..Player.Name.."' is still alive.")
            else
                table.remove(AlivePlayers, Player, Placement)
            end
        end
    else
        table.remove(AlivePlayers, Player, Placement)
    end
end

You may have noticed I've spruced it up just a bit, some more efficient methods, like ipairs.

I also may not exactly be an expert at table looping, yet I believe the second argument of the table consists of the instance, not the index, the third is also an optional choice, if not, then just revert it, or try switching 'Placement' to Player instead?

Hope this works, again go easy on me, if everything works out, don't forget to acept the answer and upvote, help me help you:)

Ad

Answer this question