Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my script only affect the second joined person GUI? (SOLVED)

Asked by
Xapelize 2658 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

Self-explanatory question. The script only affect for the second joined user. The script is:

01x = 20
02local ScreenGui = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui")
03local allplayers = game.Workspace.Values.TotalPlayers.Value
04 
05function 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
13end
14 
15function checkplayer()
View all 28 lines...
0
If you have any questions about my script or you want some more details, question in comments Xapelize 2658 — 4y
1
Alr testin it right now MiAiHsIs1226 189 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Alright. I have no idea what the problem is but here is the script that worked for me.

01x = 20
02ScreenGui = script.Parent
03allplayers = #game.Players:GetPlayers()
04function 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
13end
14function checkplayer()
15    if allplayers > 2 then
View all 25 lines...
0
Uhmm... sorry 'bout that but I knew the answer. Thanks for answering though. There is a better solution by the other guy, but he didn't post answer up here. Sorry but I can't make you as the correct answer. But I still upvoted! Thanks for helping though. <3 Xapelize 2658 — 4y
Ad
Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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:

01Players.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
06end)
07 
08Players.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
13end)

Answer this question