Help on Serverwide Schedule

Hello, I am scripting a schedule system that changes a GUI when the schedule changes. I was wondering how to get this code past the client boundry and make it serverwide because when I change the client to the server it still says “Lights Out 12:00:00” which I can’t seem to fix

local lockdown = script.Parent.Parent.lockdown.Value

Period = game.StarterGui.ScreenGui.Frame.Period.Text

game:GetService('Lighting'):GetPropertyChangedSignal('ClockTime'):Connect(function()
local CurrentTime = game.Lighting.ClockTime
if CurrentTime == 7 and lockdown == false then
	Period = "Mealtime"
	game.Workspace.Music.Night:Stop()
	game.Workspace.Music.Meal:Play()
			
elseif CurrentTime == 9 and lockdown == false  then 
	Period = "Yardtime"
	game.Workspace.Music.Meal:Stop()
	game.Workspace.Music.Freetime:Play()
	
elseif CurrentTime == 12 and lockdown == false then
	Period = "Mealtime"
	game.Workspace.Music.Meal:Play()
	game.Workspace.Music.Freetime:Stop()
	
elseif CurrentTime == 14 and lockdown == false then
	Period = "Freetime"	
	game.Workspace.Music.Meal:Stop()
	game.Workspace.Music.Freetime:Play()
	
elseif CurrentTime == 18 and lockdown == false then
	Period = "Mealtime"
	game.Workspace.Music.Meal:Play()
	game.Workspace.Music.Freetime:Stop()
	
elseif CurrentTime == 20 and lockdown == false then
	game.Workspace.Music.Meal:Stop()
	game.Workspace.Music.Cells:Play()
	Period = "Celltime"

elseif CurrentTime == 21 and lockdown == false then
	Period = "Lights Out"
	game.Workspace.Music.Cells:Stop()
	game.Workspace.Music.Night:Play()
end
end)

this is what the schedule GUI looks like
image

The time also changes to Lights Out permanently no matter the time of day when you die

Have you tried Period.Text = "string"? I don’t believe you can directly edit text using a variable.

ClockTime can be a non-integral value as well, you might want to account for that, by using the >= and <= operators and you have another issue.

You are wrongly assuming that lockdown and Period are references to the respective BoolValue.Value and TextLabel.Text properties, and that by reassigning the variables, the properties should change. What you must do is have your lockdown and Period variables contain a reference to the BoolValue and TextLabel respectively, and to get/set the value/text, make a direct access for it via lockdown.Value / Period.Text

When you assign the variables, the variables only get the values of the properties at runtime and they never update if the property changes, and the properties don’t change if the variable is reassigned.

References vs Values

References

Tables are an example of what Lua passes by reference.

t = {"this", "is", "some", "text"};
t2 = {"this", "is", "some", "text"};
t_ref = t;
table.insert(t_ref, "more text");
print(table.concat(t_ref, '\n')); -- separate each element with a newline
--[[
this
is
some
text
more text
--]]
print(table.concat(t, '\n'));
--[[
this
is
some
text
more text
--]]
print(t_ref == t, rawequal(t_ref, t)); --> true
print(t == t2, t_ref == t2); --> false
print({} == {}); --> false

t_ref and t contain a reference to the same exact table. t2 contains a reference to a different table, even if it has the same exact elements and in the same exact position.

Values

Datatypes like strings and booleans for example are not passed by reference:

s = "Text!";
s2 = s;
s = "Another Text!";
print(s2, s); --> Text!    Another Text!
print("dog" == "dog");

b = true;
b2 = b;
b = false;
print(b2, b); --> true    false
print(false == false); --> true

The variables contain different memory, so the reassignment of s and b do not reassign s2 and b2.

1 Like

my previous code has

script.Parent.Text = "Blah blah blah"

but it still didnt update past the client boundry

From what I have heard, you can’t assign .Text or .Value to a variable. Try fixing your variable by removing .Text.

For example:

Period = game.StarterGui.ScreenGui.Frame.Period.Text

Becomes:

Period =game.StarterGui.ScreenGui.Frame.Period


Now, when you have to change the text, instead of doing
Period = ""
try doing
Period.Text = ""


Correct me if I’m wrong.

I just changed it back to

script.Parent.Text = "string" 

for now