Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Text in a Text Textlabel for the screen GUI not updating. Why is that?

I am trying to build a schedule for my game, and I came up with a solution like this:

local lighting = game:GetService("Lighting")
local current = game.StarterGui.Schedule.viewschedule.current
local nexts = game.StarterGui.Schedule.viewschedule.next
local tim = lighting.ClockTime

if tim >= 7 then 
	current.Text = ("Wake Up")
	nexts.Text = ("Math Class")
end

if tim >= 8 then 
	current.Text = ("Math Class")
	nexts.Text = ("Study Hall")
end 

if tim >= 10 then 
	current.Text = ("Study Hall")
	nexts.Text = ("Lunchtime")
end

if tim >= 12 then 
	current.Text = ("Lunchtime")
	nexts.Text = ("Reading Class")
end

if tim >= 14  and tim  <= 16 then 
	current.Text = ("Reading Class")
	nexts.Text = ("Science Class")
end

if time >= 16 then
	current.Text = ("Science Class")
	nexts.Text = ("Dinner")
end

if time >= 18 then 
	current.Text = ("Dinner")
	nexts.Text = ("Party Time")
end

if time >= 20 then
	current.Text = ("Party Time")
	nexts.Text = ("Bed Time")
end

if time >= 22 then
	current.Text = ("Bed Time")
	nexts.Text = ("Wake Up")
end

When I test it in game, the text will not update. It starts on Reading Class and Science Class because the test starts at 15 on the Clock Time, but it won't update when it turns to 16. Why is that?

1 comment

0

Use a .Changed look on the API that is my guess but i don't know if anything you are making a variable for exists try adding print test through each line to identify where it stops and tell me the output error if there is any. You must learn to debug

2 answers

Hey there, bobthetomato5

If you haven't noticed already, on line 31 and so forth you start saying time instead of tim. You are not referencing your variable correctly. Please leave comments if you have any more issues.

1 comment

0

Thanks for catching that. I tried it but it did nothing. The text will still not update.

Alright, hello Bob. So, StarterGui is only updated when the player joins/respawns. To change the text in a gui for all players, you will have to do something like this.

local lighting = game:GetService("Lighting")
local tim = lighting.ClockTime

function changeText(current, nexts)
	for i,v in pairs(game.Players:GetPlayers()) do
		v.PlayerGui.Schedule.viewschedule.current.Text = current
		v.PlayerGui.Schedule.viewschedule.next.Text = nexts
	end
end

if tim >= 7 then
	changeText("Wake Up", "Math Class") -- So basically you do changeText(current text, next text)
end

if tim >= 8 then
	changeText("Math Class", "Study Hall")
end

if tim >= 10 then
	changeText("Study Hall", "Lunchtime")
end

-- I believe you can do the rest yourself

1 comment

0

Thank you. But it still will not update. Should this script be in the Starter GUI or server script service?

This discussion is preserved as it was. New answers, comments, and votes are closed.