Self-explanatory question. The script only affect for the second joined user. The script is:
x = 20 local ScreenGui = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui") local allplayers = game.Workspace.Values.TotalPlayers.Value function intermission() repeat wait(1) ScreenGui.TextLabel.Text = "Game starting in ".. x .. " seconds." x = x - 1 until x == -1 if allplayers > 1 then ScreenGui.TextLabel.Text = "Game starting!" end end function checkplayer() if allplayers > 1 then intermission() end if allplayers < 2 then print("Not enough players! ".. 2 - allplayers .." more player are needed") ScreenGui.TextLabel.Text = "Not enough players! ".. 2 - allplayers .." more player are needed to start the game." repeat wait(1) until allplayers > 1 intermission() end end checkplayer()
Alright. I have no idea what the problem is but here is the script that worked for me.
x = 20 ScreenGui = script.Parent allplayers = #game.Players:GetPlayers() function intermission() for i = x,0,-1 do wait(1) ScreenGui.TextLabel.Text = "Game starting in " .. i .. " second(s)!" end if allplayers == 1 then ScreenGui.TextLabel.Text = "Game starting!" print('Worked') end end function checkplayer() if allplayers > 2 then intermission() end if allplayers < 2 then print("Not enough players! ".. 2 - allplayers .." more player are needed") ScreenGui.TextLabel.Text = "Not enough players! ".. 2 - allplayers .." more player are needed to start the game." repeat wait(1) until allplayers > 2 intermission() end end checkplayer()
Alright guys. I got the answer.
Basically, the allplayers
value didn't update. So thats why the first person joined still stuck in the value 1 while the second one is stuck in the 2 value variable.
So I made a simple script that update the allplayers value for everyone when someone joined / left.
The script:
Players.PlayerAdded:Connect(function(Player) AmountOfPlayer = AmountOfPlayer + 1 print("A person has joined the game! Total player in server currently is ".. AmountOfPlayer.. ".") value.Value = AmountOfPlayer allplayers = game.Workspace.Values.TotalPlayers.Value end) Players.PlayerRemoving:Connect(function(Player) AmountOfPlayer = AmountOfPlayer - 1 print("A person has left the game! Total player in server currently is ".. AmountOfPlayer.. ".") value.Value = AmountOfPlayer allplayers = game.Workspace.Values.TotalPlayers.Value end)