First off, you want to add a wait inside of the Loop, if you don’t then it will finish all 45 loops in a split second and it will look like the timer never changed. Secondly, StarterGui isn’t what the player sees. When a player joins, everything from the StarterGui is cloned into their PlayerGui, so you want to use their PlayerGui instead.
Local Script:
local player = game.Players.LocalPlayer
local stageText = player.PlayerGui.SpeedGUI.TimerFrame.StageLabel
local timerText = stageText.Parent.TimerLabel
for i = 1, 45 do
wait(1)
timerText.Text = i
end
I have a few questions about this, and this may be due to me not explaining the problem correctly. I want the gui on the left to say ‘Intermission’, and the gui on the right to display how much time is left.
Why would I want to make a it a localscript when I want everybody to see it? Also, I can’t seem to find out where playerGui is in the explorer.
Thanks for catching me on the wait inside of the for loop though
local stageText = game.StarterGui.SpeedGUI.TimerFrame.StageLabel
local timerText = game.StarterGui.SpeedGUI.TimerFrame.TimerLabel
game.StarterGui.SpeedGUI.ButtonCollection.ButtonRace.Visible = false
stageText.Text = 'Intermission'
for time = 1, 45 do
wait(1)
timerText.Text = tostring(time)
end
Interesting. Here is the code now:
function intermission()
local stageText = game.StarterGui.SpeedGUI.TimerFrame.StageLabel
local timerText = game.StarterGui.SpeedGUI.TimerFrame.TimerLabel
game.StarterGui.SpeedGUI.ButtonCollection.ButtonRace.Visible = false
stageText.Text = 'Intermission'
for time = 45, 1, -1 do
wait(1)
timerText.Text = tostring(time)
end
Thank you to all who helped, especially @YouCantEscapeUS_DGL , because his script worked 80%. I think that the reason the textlabel wasn’t displaying ‘Intermission’ was that I was trying to create the property .Text inside of the actual variable.
Hopefully I can fix the for loop issue soon, I will post back on here when I do.
Oops, I see that you are changing the StarterGui and not the actual player’s GUI.
The best solution is to create a NumberValue called Time in ReplicatedStorage , a BoolValue called Visible in ReplicatedStorage and a StringValue called ST in ReplicatedStorage,
Change the Script to
function intermission()
local Time = game:GetService("ReplicatedStorage"):WaitForChild("Time") -- To get the Time Value
local Visible = game:GetService("ReplicatedStorage"):WaitForChild("Visible") -- To get the Visible Value
local StageText = game:GetService("ReplicatedStorage"):WaitForChild("ST") -- To get the StageText Value
Visible.Value = true
StageText.Value = 'Intermission'
for time = 45, 1, -1 do
wait(1)
Time.Value = tostring(time)
end
end
Create a LocalScript in TimerLabel with the script
local Text = game:GetService("ReplicatedStorage"):WaitForChild("Time")
game:GetService("RunService").HeartBeat:Connect(function()
script.Parent.Text = tostring(Text.Value)
end)
And finnaly create a LocalScript in StageLabel with the script
local Text = game:GetService("ReplicatedStorage"):WaitForChild("Time")
local Visible = game:GetService("ReplicatedStorage"):WaitForChild("Visible")
game:GetService("RunService").HeartBeat:Connect(function()
script.Parent.Text = tostring(Text.Value)
script.Parent.Visible = Visible.Value
end)
It has come to my attention that I can use the intermission() function for stuff like teleporting players, but I will need to create a localscript to update the ui. Thank you all for your help
Perhaps as a next step, if you’re feeling a bit adventurous.
A statemachine works well for lobby systems and let you manage the state of the lobby more closely.
Take this snippet as an example.
Lobby.fsm.intermission:Connect(function(fsm, name, from, to, ...)
if name ~= "intermission" then return end
-- Do this during an intermission.
Lobby.Counter = Lobby.IntermissionTimer
end)
Lobby.fsm:transition("intermission")