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

How to make text change when time changes?

Hello,

I have been trying to put a script into a TextLabel in a Gui, where when the Roblox ClockTime reaches a certain value, it changes the text. However, it does not work. I have already implemented a Day/Night script. Please help!

L = game:WaitForChild("Lighting")

while true do
	if L.ClockTime == 6 then
		script.Parent.Text = "Text1"
	elseif L.ClockTime == 7 then
		script.Parent.Text = "Text2"
	elseif L.ClockTime == 8 then
		script.Parent.Text = "Text3"
	elseif L.ClockTime == 10 then
		script.Parent.Text = "Text4"
	elseif L.ClockTime == 13 then
		script.Parent.Text = "Text5"
	elseif L.ClockTime == 14 then
		script.Parent.Text = "Text6"
	elseif L.ClockTime == 17 then
		script.Parent.Text = "Text7"
	elseif L.ClockTime == 18 then
		script.Parent.Text = "Text8"
	elseif L.ClockTime == 19 then
		script.Parent.Text = "Text19"
	end
end

2 comments

0

Is your game crashing every time you try to run this?

0

the while true do caused that you crash the game.

2 answers

✓ Accepted answer

Hello, I'll tell you the working script, but wait, before this, I'll tell you, why this script is not working.

You did a very big problem. Why do you do while true do ??!?!! It was updating the script mostly 0 seconds, and it might cause very much lag.

Next, Lightning is a service, and that's already at the workspace, before running the game. So make that become game:GetService("Lightning")

So, the correct script is like this

L = game:GetService("Lighting") -- become GetService instead of WaitForChild

while wait(.5) do -- make it update the script every 0.5 seconds.
    if L.ClockTime == 6 then
        script.Parent.Text = "Text1"
    elseif L.ClockTime == 7 then
        script.Parent.Text = "Text2"
    elseif L.ClockTime == 8 then
        script.Parent.Text = "Text3"
    elseif L.ClockTime == 10 then
        script.Parent.Text = "Text4"
    elseif L.ClockTime == 13 then
        script.Parent.Text = "Text5"
    elseif L.ClockTime == 14 then
        script.Parent.Text = "Text6"
    elseif L.ClockTime == 17 then
        script.Parent.Text = "Text7"
    elseif L.ClockTime == 18 then
        script.Parent.Text = "Text8"
    elseif L.ClockTime == 19 then
        script.Parent.Text = "Text19"
    end
end

-- everything else is nice! ;)

-- this I tested in rblx studio, so 100% works.

If you have other questions, or need a better explanation, PM to my profile, or ask below the comments!

So, cyaaa~

2 comments

0

The better option is to use GetPropertyChangedSignal() on ClockTime instead of polling for it.

0

Thanks for the tip, BashCaster, I'll try my best to learn my LUA, lol...

Try this:

L = game:WaitForChild("Lighting")

while true do
   wait(1)
   local current = L.ClockTime
   if current == current + 1 then
        TextLabel.Text = "Time 1"
   end
end

But be aware this may not work as I am new, and also it might not be the correct indentation so you might want to type this out yourself.

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