This works
local gametime = game.Lighting.ClockTime while wait(1)do if(game.Lighting.ClockTime > 6.3)and(game.Lighting.ClockTime < 17.3)then window.Color = Color3.new(0.231373, 0.603922, 0.635294) window.Material = Enum.Material.SmoothPlastic else window.Color = Color3.new(0.741176, 0.698039, 0.192157) window.Material = Enum.Material.Neon end end
But this doesn't
local window = game.Workspace.Window local gametime = game.Lighting.ClockTime while wait(1)do if(gametime > 6.3)and(gametime < 17.3)then window.Color = Color3.new(0.231373, 0.603922, 0.635294) window.Material = Enum.Material.SmoothPlastic else window.Color = Color3.new(0.741176, 0.698039, 0.192157) window.Material = Enum.Material.Neon end end
======================== Can someone explain why it won't work with a variable?
If possible super simply, I just started scripting a few days ago!
Well, the problem, here, is that you are declaring a variable for the ClockTime
when the game loads, i.e., 14
[Default]. So, your variable will remain fixed to 14
[Default] only and it won't change as there is no Function
or Event
to trigger/update the variable again.
So, what's the fix?
Well, declare your variable inside the while
loop to get it updated everytime. This is how your code must look :
local window = game.Workspace.Window while wait(1)do local gametime = game.Lighting.ClockTime if(gametime > 6.3)and(gametime < 17.3)then window.Color = Color3.new(0.231373, 0.603922, 0.635294) window.Material = Enum.Material.SmoothPlastic else window.Color = Color3.new(0.741176, 0.698039, 0.192157) window.Material = Enum.Material.Neon end end
Lemme know if it helps!
EDIT : You can use GetPropertyChangedSignal
instead of while
loop, to reduce memory usage/stress.
--// Variables local Lightning = game:GetService('Lightning') local window = workspace.Window --// Functions local function onChanged() local gametime = Lightning.ClockTime if (gametime > 6.3) and (gametime < 17.3) then window.Color = Color3.new(0.231373, 0.603922, 0.635294) window.Material = Enum.Material.SmoothPlastic else window.Color = Color3.new(0.741176, 0.698039, 0.192157) window.Material = Enum.Material.Neon end end --// Main Lightning:GetPropertyChangedSignal('ClockTime'):Connect(onChanged) -- Triggers everytime whenever the 'ClockTime' value is changed!