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

Trying to set text to something depending on ClockTime like Prison Life isn't working?

So I'm doing something similar to what Prison Life does, with the events thing. My code isn't working.

Here is the code:

local text = script.Parent.Text
local clocktime = game.Lighting.ClockTime

while wait() do
	if clocktime == 6 then
		text = "Breakfast"
	elseif clocktime == 8 then
		text = "Free Time"
	end
	
	if clocktime == 12 then
		text = "Lunch"
	elseif clocktime == 14 then
		text = "Yard Time"
	end
	
	if clocktime == 17 then
		text = "Dinner Time"
	elseif clocktime == 18 then
		text = "Free Time"
	end
	
	if clocktime == 22 then
		text = "Lights Out"
	end
end

send help

3 comments

0

Is ClockTime a Value?

0

no clocktime is lighting

0

ClockTime is a number value that is the current hour of the game, the lighting changes depending on the hour

1 answer

I believe you are updating the variable in that script. You originally set text to equal script.Parent.Text but every time you say text = ... then it updates the variable to a string. So if you want to update the text you would have to replace text with script.Parent.Text

Also so this will show for all players on a FE game, please consider learning about RemoteEvents. To update something like this for every client you would use a function called FireAllClients(). Read about them here

Edited code:

local text = script.Parent.Text
local clocktime = game.Lighting.ClockTime

while wait() do
    if clocktime == 6 then
        script.Parent.Text = "Breakfast"
    elseif clocktime == 8 then
        script.Parent.Text = "Free Time"
    end

    if clocktime == 12 then
        script.Parent.Text = "Lunch"
    elseif clocktime == 14 then
        script.Parent.Text = "Yard Time"
    end

    if clocktime == 17 then
        script.Parent.Text = "Dinner Time"
    elseif clocktime == 18 then
        script.Parent.Text = "Free Time"
    end


    if clocktime == 22 then
        script.Parent.Text = "Lights Out"
    end
end

2 comments

0

doesn't work! :'(

0

Maybe instead of using while, try using game.Lighting.ClockTime.Changed:Connect(function())

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