Lobby Script minimum number of players not working?
I have created a script which assigns the boolean 'playing' to each player when the enter the server. When they click the GUI button 'start' this changes to true, however this is not the problem.
My main server script for the execution of the game calls an error because (as far as I am aware) the script is performed on the player before my other script assigns the 'playing' bool to them when they join. I have a bad workaround this by adding a temporary 'wait' for 10 seconds for them to load in fully and be assigned the 'playing' bool but this still crashes if another player joins after that first 10 seconds as it constantly loops through checking if the players have the variable.
05 | players = game.Players:GetChildren() |
07 | for i = 1 , # players do |
08 | local playing = players [ i ] .playing.Value |
09 | if playing = = true then |
10 | table.insert(playingPlayers, players [ i ] ) |
13 | lobbyAmount = tablelength(playingPlayers) |
15 | if lobbyAmount < 2 then |
16 | print ( "Not enough players" ) |
This is the main server script ^
1 | game.Players.PlayerAdded:Connect( function (player) |
2 | player.CharacterAdded:Connect( function (modelPlayer) |
3 | local playing = Instance.new( "BoolValue" ) |
4 | playing.Name = "playing" |
5 | playing.Parent = player |
This is the other script that assigns the bool to the player. ^
It crashes on 'local playing = players[i].playing.Value as when the player first joins the other script doesn't have time to assign that variable to them (I think that's what is happening anyway). I'm pretty stuck on how to solve this, any help would be appreciated thanks!