How to see if every player has BoolValue true?

I want to setup a code where the script checks if every player has BoolValue true before proceeding do things.

What I tried:
for i,v in pairs (AllPlrs) do but if the last player in the table has BoolValue true, while the rest doesn’t the game proceeds anyway, which I don’t want.

you could check and if it’s true set it to false then set everyone’s BoolValue to true

If I understand correctly, you want all players to have the BoolValue to be true, not just one to proceed.
You can make a variable so that each time a player has a true BoolValue, it increases by 1. And then compare that variable to the number of players.

I assume the problem is that you’re doing your check and progression straight from the for loop, meaning that if someone passes your evaluation in that iteration then the script will take that as a signal to continue. That’s why the last player allows the game to proceed.

What you should be doing here is using a single boolean variable to determine if the game should proceed or wait until players are ready. Your for loop should only help determine what the value is this boolean is and the game should proceed based on what said value is.

Take this function for example:

local function getAllPlayersAreReady()
    local allPlayersAreReady = true

    for _, player in ipairs(players) do
        if not BoolValue.Value then
            allPlayersAreReady = false
            break
        end
    end

    return allPlayersAreReady
end

This code assumes that all players are ready (have their BoolValues true), then loops over all the players. If the player of the current loop’s iteration does not have true for their BoolValue, then it sets the earlier variable to false and stops the loop early. Then, whatever the final value is after everything has completed in the function is returned back.

local playersAreReady = getAllPlayersAreReady()

if playersAreReady then
    print("Begin the party")
end
6 Likes

And another trick learned for me.