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

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

Asked by 3 years ago

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?

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 Coder_1 27 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

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.

0
Thanks for catching that. I tried it but it did nothing. The text will still not update. bobthetomato5 7 — 3y
Ad
Log in to vote
0
Answered by
Torren_Mr 334 Moderation Voter
3 years ago

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
0
Thank you. But it still will not update. Should this script be in the Starter GUI or server script service? bobthetomato5 7 — 3y

Answer this question