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

Why is my simple script for a gui not working?

Asked by 8 years 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

3 answers

Log in to vote
0
Answered by 8 years 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 364 Moderation Voter
8 years ago
Edited 8 years 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 129 — 8y
Log in to vote
0
Answered by
FiredDusk 1466 Moderation Voter
8 years 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