I'm having trouble and I have tried multiple types of loops but nothing seems to work, basically I am trying to have a
while true do -- if 2 players have 'CanPlay' set to true then -- continue code.
which runs through the players and searches to see if their value "CanPlay" boolvalue is set to true. I know this sounds like a request, but it's not.. and I tried! Please leave help if you can!
My attempts:
if game.Players.NumPlayers >= PlayerNumber and game.Players.NumPlayers.CanPlay == true then then -- Wasn't sure.. -- Tried using loops, the while true do loop is the entire game I have setup. while true do if game.Players.NumPlayers >= PlayerNumber then for i, v in pairs(game.Players:GetPlayers()) do if v.CanPlay.Value == true then -- Not sure how to continue. end end -- Code else end
First off, I'd split this into two functions, one to check if there are enough players with CanPlay set to true, and another to loop until the first function returns true.
function enoughPlayers() end function waitUntilEnoughPlayers() while not enoughPlayers() do wait() end end
Okay, now to make the enoughPlayers
function work. You're off to a good start with looping through each player and checking who has CanPlay set to true. Next I'd make a number variable count up for each player that has CanPlay set to true.
function enoughPlayers() local playing = 0 for i, v in pairs(game.Players:GetPlayers()) do local CanPlay = v:FindFirstChild("CanPlay") -- let's be safe and check if the CanPlay BooleanValue exists first aswell if CanPlay and CanPlay.Value then playing = playing+1 end end return playing >= 2 -- this makes the function return true if the playing variable is greater than or equal to 2, otherwise it will return false end