Having race conditions like these are very troublesome and I wouldn’t recomend doing this but, you could tag the bold values with CollectionService and asynchronously loop through them, this is a sloppy implementation:
local totalValues = 12
local counter = 0
for _, bool in pairs(CollectionService:GetTagged("BoolValues")) do
if bool.Value then
counter += 1
end
end
if counter == totalValues then
doSomething()
end
Thanks, but could you please explain what i need to do or change in that script in order for it to work, i have never used CollectionService before and i’m a bit confused in general.
Hm, I believe what you could do is get the children of all the values inside your values Folder (I’m assuming), and use a Changed Event to check if all of them are equal to true? Not sure on how to do it though, which is the thing
game.Players.PlayerAdded:Connect(function(Player)
local Connection
local values = player:WaitForChild("values")
local ActivatedBools = 0
local TotalBools = #values:GetChildren()
for _, Bool in pairs(values:GetChildren()) do
local function Changed(NewValue)
if NewValue == false then
ActivatedBools -= 1
else
ActivatedBools += 1
end
print("Activated Bools: "..ActivatedBools)
if ActivatedBools == TotalValues then
Connection:Disconnect()
break
end
end
Connection = Bool.Changed:Connect(Changed)
end
print(Player.Name.." has enough BoolValues!")
end)
Or just something relevant to what @ObedientDavid_B suggested
game.Players.PlayerAdded:Connect(function(Player)
local Connection
local values = player:WaitForChild("values")
local ActivatedBools = 0
local TotalBools = #values:GetChildren()
for _, Bool in pairs(values:GetChildren()) do
local function Changed(NewValue)
if NewValue == false then
ActivatedBools -= 1
else
ActivatedBools += 1
end
print("Activated Bools: "..ActivatedBools)
if ActivatedBools == TotalValues then
Connection:Disconnect()
end
end
Connection = Bool.Changed:Connect(Changed)
end
while ActivatedBools ~= TotalBools do
print(Player.Name.." does not have enough BoolValues!")
wait(1)
end
print(Player.Name.." has enough BoolValues!")
end)
I’ll send you yhe script i’m using with some modifications:
local service = game:GetService("BadgeService")
local badgeid = 2124707878
game.Players.PlayerAdded:Connect(function(Player)
local Connection
local values = Player:WaitForChild("eggHuntLB")
local ActivatedBools = 0
local TotalBools = #values:GetChildren()
for _, Bool in pairs(values:GetChildren()) do
local function Changed(NewValue)
if NewValue == false then
ActivatedBools -= 1
else
ActivatedBools += 1
end
print("Activated Bools: "..ActivatedBools)
if ActivatedBools == TotalBools then
Connection:Disconnect()
end
end
Connection = Bool.Changed:Connect(Changed)
end
while ActivatedBools ~= TotalBools do
print(Player.Name.." does not have enough BoolValues!")
wait(1)
end
print(Player.Name.." has enough BoolValues!")
service:AwardBadge(Player.UserId, badgeid)
end)