Check if all players in table have their BoolValue set to true?

Hello developers! So I am working on my AI, and I need to check if all players in table have their BoolValue set to true.

1 Like

Lots of different ways of doing this I guess, I’d go with something like this:

local function CheckPlayerBools(PlayerTable)

	for _,plr in ipairs(PlayerTable) do
		if plr.MyBoolValue.Value==false then return end -- a player's boolvalue is false so return false as all players aren't true
	end
	return true -- all players have true boolvalues
	
end

Simply call the function with the players table and it will return true if all bools are true or false if not.
Remember to change the MyBoolValue to whatever/wherever your values are stored.

Im trying to make a system in which a player is downed they set a bool value to true. And in server script service im trying to make a loop where it loops through all the players in the game and once all the players in the game has there downed value set to true then itll make a gui appear. So could you explain how to do it a little clearer @ZombieCrunchUK

Without seeing your current code it’s a little difficult to be specific but it would be something like this:

local Players=game:GetService("Players")


local function CheckPlayerBools()

	for _,plr in ipairs(Players:GetPlayers()) do
		if plr.MyBoolValue.Value==false then return end -- a player's boolvalue is false so return false as all players aren't true
	end
	return true -- all players have true boolvalues

end


local EveryoneDown=false

 -- The following loop will repeat until all players BoolValue=true
repeat
	
	EveryoneDown=CheckPlayerBools()
	task.wait()
	
until EveryoneDown

-- script will continue when EveryoneDown=true so add code here to show guis
1 Like