How to check if all players has a boolValue true

I want to check if all players has a true value. For now it doesn’t work at all

local allTrue = true
	for i, plr in pairs(game.Players:GetPlayers()) do
		if not plr.BoolValue.Value then
			allTrue = false
		end
	end

if allTrue then
	replicatedStorage.FireClientCutscene:FireClient()
end
1 Like

Isn’t :FireClient() supposed to be :FireAllClients() instead?

That still doesn’t work apparently. Could it be that for loop runs only once and get’s allTrue value “false” so it doesn’t fire it?

you posted same thing what I’ve posted. FireAllClients() doesn’t change anything :confused:

FireAllClients is the only way you can fire a remote event without any player arguments.

local allTrue = true
local value
for _, player in ipairs(game.Players:GetPlayers()) do
	value = player:FindFirstChild("BoolValue")
	if (not (value and value.Value)) then
		allTrue = false
		break
	end
end
if (allTrue) then
	replicatedStorage.FireClientCutscene:FireAllClients()
end

that doesn’t seem to work. I’ve tried to put boolvalue in serverstorage and see if this code changes value to “true” but it doesnt. :confused:

What’s the context of your code? What are you actually trying to do? Why does each player need to have a bool value?

2 Likes

I hope this may help? It was a bit hard to understand what you’re trying to achieve but let me know if I got this right.

local NotEnough = false

for i, player in pairs(game.Players:GetPlayers()) do
	if player.BoolValue.Value == false then
		print(player.Name.." has their BoolValue equal to false")
		NotEnough = true
		break
	else
		wait()
	end
end

if NotEnough == false then --this basically means if they're all set to true
	-- your action here
end
1 Like

Shouldn’t it be ipairs and not pairs?

It shouldn’t really make a difference, since the code shouldn’t really encounter a nil player within :GetPlayers(), and if it did it should skip it instead of stopping dead in it’s tracks like with ipairs() - they both search through the table linearly in a similar manner.

1 Like