Say every player gets a bool value, how would I check if every single one of them has theirs set to true?
Let's look at your example.
You state that you want to check if every player has a BoolValue set to true (assumably within their player instance).
We can do this multiple ways, but let's start simple.
local SameValue = true for _,Player in pairs(game:GetService("Players"):GetPlayers()) do if Player:FindFirstChild("BoolValue").Value == false then SameValue = false end end
This code will essentially iterate each player inside of Players, and if any of them have the value as false - SameValue will become false. This will provide you whether all players have a BoolValue set to true (because if after running this for loop SameValue is stated as false, then at least one value is not true).
We could also make it a bit more complicated and applicable by genuinely checking to see if all players have the same value.
local CurrentVals = {} local SameValue = true for _,Player in pairs(game:GetService("Players"):GetPlayers()) do CurrentVals[#CurrentVals + 1] = Player:FindFirstChild("BoolValue").Value end local SelectedValue = Random.new():NextInteger(1, #CurrentVals) for _,TableIndex in pairs(CurrentVals) do if TableIndex ~= CurrentVals[SelectedValue] then SameValue = false end end
The code above will start by creating a table of all player's values. It will then choose a random index from the table, and compare it to every value in the table. If at any junction the randomly selected table index is not the same as some table index - SameValue will become false - meaning that every value in the table is not the same.
(there may be some syntax mistakes since I wrote this relatively fast without testing - but hopefully you get an idea of what I mean)
This code might be inefficient but it was the best I could come up with.
local Players = game.Players:GetPlayers() local TrueValues = 0 for _, Players in pairs(game.Players:GetPlayers()) do if Player:FindFirstChild("BoolValue") then local BoolValue = Player:FindFirstChild("BoolValue") if BoolValue.Value == true then TrueValues = TrueValues + 1 end end end do -- You can remove this if this code is being executed (Along with the end) if TrueValues == #Players then print('All values are true') end end -- This end
for _,v in pairs(game.Players:GetPlayers()) do if v[ "My Bool Value" ].Value == true then print':D' end end