Self-explanatory question. The script only affect for the second joined user. The script is:
01 | x = 20 |
02 | local ScreenGui = game.Players.LocalPlayer.PlayerGui:WaitForChild( "ScreenGui" ) |
03 | local allplayers = game.Workspace.Values.TotalPlayers.Value |
04 |
05 | function intermission() |
06 | repeat wait( 1 ) |
07 | ScreenGui.TextLabel.Text = "Game starting in " .. x .. " seconds." |
08 | x = x - 1 |
09 | until x = = - 1 |
10 | if allplayers > 1 then |
11 | ScreenGui.TextLabel.Text = "Game starting!" |
12 | end |
13 | end |
14 |
15 | function checkplayer() |
Alright. I have no idea what the problem is but here is the script that worked for me.
01 | x = 20 |
02 | ScreenGui = script.Parent |
03 | allplayers = #game.Players:GetPlayers() |
04 | function intermission() |
05 | for i = x, 0 ,- 1 do |
06 | wait( 1 ) |
07 | ScreenGui.TextLabel.Text = "Game starting in " .. i .. " second(s)!" |
08 | end |
09 | if allplayers = = 1 then |
10 | ScreenGui.TextLabel.Text = "Game starting!" |
11 | print ( 'Worked' ) |
12 | end |
13 | end |
14 | function checkplayer() |
15 | if allplayers > 2 then |
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:
01 | Players.PlayerAdded:Connect( function (Player) |
02 | AmountOfPlayer = AmountOfPlayer + 1 |
03 | print ( "A person has joined the game! Total player in server currently is " .. AmountOfPlayer.. "." ) |
04 | value.Value = AmountOfPlayer |
05 | allplayers = game.Workspace.Values.TotalPlayers.Value |
06 | end ) |
07 |
08 | Players.PlayerRemoving:Connect( function (Player) |
09 | AmountOfPlayer = AmountOfPlayer - 1 |
10 | print ( "A person has left the game! Total player in server currently is " .. AmountOfPlayer.. "." ) |
11 | value.Value = AmountOfPlayer |
12 | allplayers = game.Workspace.Values.TotalPlayers.Value |
13 | end ) |