The answer to this is probably really obvious, but since I'm new I can't figure it out

Hello all,

I have this problem in my code for my game under development. The game is round based.

Here is the code:

function intermission()

-- gui variables
local stageText = game.StarterGui.SpeedGUI.TimerFrame.StageLabel.Text
local timerText = game.StarterGui.SpeedGUI.TimerFrame.TimerLabel.Text

game.StarterGui.SpeedGUI.ButtonCollection.ButtonRace.Visible = false
stageText = 'Intermission'

for time = 1, 45 do
	
	timerText = time
	
end

end
intermission()

Here is the issue

And here is the explorer window:
Screenshot 2021-02-14 161817

As you can see in the code, one of the buttons has gone invisible (marked in red on the left side of the screenshot), so the function is clearly running. The problem is that (as marked in red on the top of the screenshot) neither of the guis are displaying the text I want. There are no errors in the output. Please help!

If you need any more information, feel free to ask. Hope you all are enjoying your day,
@Mithrandir6440

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 :slight_smile:

You need to write

local player = game.Players.LocalPlayer

then
instead of game.StarterGui it should be

player.PlayerGui

this should probably be in a local script but it is ok for now
let me know if there is an issue

Ah I did not realize @XdJackyboiiXd21 already mentioned this!

The devking has a great video about this, Video. Try watching this video and we can explain how it works if you have any questions.

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
1 Like

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

end

And here is the result:

The problem now? It isn’t counting down, it’s just staying at 45. Why does it need to be a localscript though?

You can take a look at my other post on playergui for reference

Could you tell me where this script is in the explorer?

I put the script in ServerScriptService

I will message you more on this

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.

1 Like

It wasn’t updating is because you were updating an Variable, not the actual text.

You sure? Because it sure looks to me that it would be updating the text not the variable…

It wouldn’t work anyway because it is not in a local script and because he is trying to startergui not the playergui

1 Like

I’m talking about the old code.

Maybe because time is a global. So the loop should change to

for t = 45, 1, -1 do
	wait(1)
	timerText.Text = tostring(t)
end

Also, format your code with ``` at the end and start.

1 Like

If you are talking to me about this, I always make sure to do so

Ah ok thanks for clarifying

To fix his local script problem he just needs to send a message from his server script to a local via a remote event

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)

Tell me if there are any issues

1 Like

I made some changes to the script, so you may need to Refresh for them to appear

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 :wink:

1 Like