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
3 years ago
Edited 3 years ago

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()
0
If you have any questions about my script or you want some more details, question in comments Xapelize 2658 — 3y
1
Alr testin it right now MiAiHsIs1226 189 — 3y

2 answers

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

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()
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 — 3y
Ad
Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
3 years ago
Edited 3 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:

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)

Answer this question