1
votes

So I typed this script(it's a normal script)to change the text when 2 players are in the game but the problem is when player 2 joins the game any later the text only changes to player 2 and nothing happens to player 1(I inserted the script in the textlabel where the textlabel will change)and when player 1 leaves the game the text does not change.Anyways here's the script:

if #game:GetService("Players"):GetPlayers() >= 2 then
script.Parent.Text ="Intermission: 25"
wait(1)
script.Parent.Text ="Intermission: 24"
wait(1)
script.Parent.Text ="Intermission: 23"
wait(1)
script.Parent.Text ="Intermission: 22"
wait(1)
script.Parent.Text ="Intermission: 21"
wait(1)
script.Parent.Text ="Intermission: 20"
wait(1)
script.Parent.Text ="Intermission: 19"
wait(1)
script.Parent.Text ="Intermission: 18"
wait(1)
script.Parent.Text ="Intermission: 17"
wait(1)
script.Parent.Text ="Intermission: 16"
wait(1)
script.Parent.Text ="Intermission: 15"
wait(1)
script.Parent.Text ="Intermission: 14"
wait(1)
script.Parent.Text ="Intermission: 13"
wait(1)
script.Parent.Text ="Intermission: 12"
wait(1)
script.Parent.Text ="Intermission: 11"
wait(1)
script.Parent.Text ="Intermission: 10"
wait(1)
script.Parent.Text ="Intermission: 9"
wait(1)
script.Parent.Text ="Intermission: 8"
wait(1)
script.Parent.Text ="Intermission: 7"
wait(1)
script.Parent.Text ="Intermission: 6"
wait(1)
script.Parent.Text ="Intermission: 5"
wait(1)
script.Parent.Text ="Intermission: 4"
wait(1)
script.Parent.Text ="Intermission: 3"
wait(1)
script.Parent.Text ="Intermission: 2"
wait(1)
script.Parent.Text ="Intermission: 1"
wait(1)
script.Parent.Text ="Intermission: 0"
else
script.Parent.Text ="Waiting for Players"
end
1
1st, a script does not loop/repeat, try adding events in. Also this is abit off topic(sorry), but I would recommend using a for loop for this task, it will save you a lot of time and lines. - ChilliPenguin
So a localscript is required for guis? - GameBuilderLol
Yes. Have a normal script detect if 2 players are in the game, then have it trigger an event. In your local script, have it listen for this event, when it hears the event edit the text. - ChilliPenguin
Also i did use localscript but the problem was when i tested the game with 2 players(2 players needed to join at the same time)The intermission was lagging behind for player 1. - GameBuilderLol
Did they join at the exact same time or was there a grace period. Also you probably want to wait for the player to loading in, as the script will probably detect the player before the 2nd player's script is loaded in. - ChilliPenguin

1 Answers

0
votes

this should fix the error(s)

local countdown = 25
local players = 0

game:GetService("Players").PlayerAdded:Connect(function()
    players = players + 1
end)

game:GetService("Players").PlayerRemoving:Connect(function()
    players = players - 1
end)

while wait(1) do
    if players > 1 then
        script.Parent.Text = "Intermission: ".. countdown
        print("Intermission: ".. countdown)
        countdown = countdown - 1
        if countdown <= 0 then
            script.Parent.Visible = false
            countdown = 25
        end
    end
    
    if players < 2 then
        script.Parent.Text = "Intermission: ".. countdown
        print("Intermission: ".. countdown)
        countdown = 25
    end
end