✓ Accepted answer
##Problem
There are a couple of problems with your script. First off, GetChildren returns a table. If you try to use .PlayerValues on a table, the script will think "oh you're looking for an object named PlayerValues right in Players". Then the script will say, "nope nothing named PlayerValues here, I have an error".
##Solution
So you want to make a function that will loop through all players in Players service to determine if there is a PlayerValues value still set to true.
##Breakdown
In the new script I've made below we are establishing a function that we can use to return a true or false value, if there is anyone with a value of true or not. Within the function there is a for loop that will go through all Player instances in the Players service. With that loop it will go into each individual player and check if the value is true, if so return false to the if then statement. If the loop is to finish then that means that no one has a value of true and the script will return to the if then statement with true. This will cause your code in the if then statement to execute and break your numerical for loop.
##Final Script
function AllPlayersFalse()
for i,v in pairs(game.Players:GetPlayers()) do
if v.PlayerValues.Playing.Value == true then
return false
end
end
return true
end
for i = 120,1,-1 do
Status.Value = i
if AllPlayersFalse() then
break
end
wait(1)
end
######Hopefully this answered your question. If so, do not forget to hit the accept answer button. If you have any other questions, feel free to leave them in the comments below. If the script errors out, then please leave the error in the comments below along with the line number it is occurring on and I will see what I can do.
4 comments
I think I understand what you're trying to accomplish, and I am able to help you out. However you haven't exactly helped me out by explaining your issue and what you plan to achieve. If you could revise your question to resolve these concerns I will be able to help you out.
You do create the value objects and set them to true at the start of the loop right? I will assume you do for the answer.
Yeah i do
In your main loop, you can create another loop where you loop through all the players, and if one of them is still playing, you continue the main loop, otherwise, break the loop.