Ad
Log in to vote
0

Why is my simple script for a gui not working?

Asked by 1 year ago

So i was just testing something out in studio with a gui, and made a script so that it becomes a countdown intermission gui. In the startergui i have a screengui named "Intermission" and inside the screengui a text label named "Countdown". The text label is set to invisible and the text is set to "Intermission: 30". So then i made this script so that it goes from 30 to 1. When i press run, it works just fine, and when i press play solo it just stays at "Intermission: 30", and when i play in the actual server, it goes to a random number, usually "Intermission: 26" and stays that way. I have no idea why, help?

game.StarterGui.Intermission.Countdown.Visible = true
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 30"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 29"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 28"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 27"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 26"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 25"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 24"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 23"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 22"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 21"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 20"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 19"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 18"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 17"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 16"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 15"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 14"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 13"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 12"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 11"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 10"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 9"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 8"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 7"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 6"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 5"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 4"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 3"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 2"
wait(1)
game.StarterGui.Intermission.Countdown.Text = "Intermission: 1"
wait(1)
game.StarterGui.Intermission.Countdown.Visible = false

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

3 answers

Log in to vote
0
Answered by 1 year ago

For an example of what StolidDarkness was speaking about,

for i,v in pairs(game.Players:GetPlayers))) do --Go through the players to enable the GUI
    v.PlayerGui.Intermission.Countdown.Visible = true
end
for i = 30,1,-1 do 
    for i,v in pairs(game.Players:GetPlayers))) do --Go through the players to change the text.
        v.PlayerGui.Intermission.Countdown.Text = "Intermission: " ..i 
    end
    wait(1)
end
for i,v in pairs(game.Players:GetPlayers))) do  --Go through the players to disable the GUI
    v.PlayerGui.Intermission.Countdown.Visible = false
end

Thanks to FiredDusk for the loop

Ad
Log in to vote
3
Answered by
StoIid 354
1 year ago
Edited 1 year ago

This is because you are editing the gui that is located in StarterGui. You only get a copy of the gui's you place in StarterGui same goes for StarterPack.

When you change the text of the gui in the StarterGui it is not going to show for you because you do not have a copy of the now edited gui. If you want the edits to show you have to edit the Players gui located in PlayerGui (game.Players.PlayerName.PlayerGui)

To do this all at once and use a single script (the "efficient way" -Pyrondon) you're going to need to use a loop.

Info On Loops

0
Oh i see now Supergamerboy1995 120 — 1y
Log in to vote
0
Answered by
FiredDusk 1396
1 year ago

A better way of writing that code is:

game.StarterGui.Intermission.Countdown.Visible = true
for i = 30,1,-1 do --Another way of going from 30 to 1 by counting down.
    game.StarterGui.Intermission.Countdown.Text = "Intermission: " ..i --This is what changes the numbers
    wait(1)
end
game.StarterGui.Intermission.Countdown.Visible = false

Answer this question



Ad