My script:
local part = script.Parent while true do wait(0.1) if game.Lighting.ClockTime < 6.1 then game.ReplicatedStorage.MoonScript.Parent = game.Workspace.TelescopeLookoutTeleporter part.SunScript.Parent = game.ReplicatedStorage end if game.Lighting.ClockTime > 6 then game.ReplicatedStorage.SunScript.Parent = part part.MoonScript.Parent = game.ReplicatedStorage end end
You should consider putting them in the same script. I know you probably seperated them due the the loop, so let’s replace the loops.
An alternative would be to use coroutine
, but in this case, :GetPropertyChangedSignal
is a better choice.
local Lighting = game:GetService(‘Lighting’) Lighting:GetPropertyChangedSignal(‘ClockTime’):Connect(function() --Whenever ClockTime changes, this event will fire, effectively replacing a loop if Lighting.ClockTime < 6.1 then --do stuff originally in “MoonScript” and stop whatever is in “SunScript” elseif Lighting.ClockTime > 6 then --do stuff originally in “SunScript” and stop whatever is in “MoonScript” end end)