local lighting = game.Workspace.Model local light = lighting.LightPart local timeOutput = game.Lighting:GetMinutesAfterMidnight() local nightStandard = 6 local dayStandard = 18 local num = 2 local function DayNightCycle() while wait(.2) do num = num + 1 game.Lighting:SetMinutesAfterMidnight(num *60) print(game.Lighting.TimeOfDay) end end local function bindToTime() print("binded") end while wait(1) do bindToTime() end DayNightCycle()
For some explanation, I'd like to add that switch the bindToTime function being called and DayNightCycle does matter, because if I add DayNightCycle() first, bindToTime() won't work. How can I prevent from one function being called automatically stopping the entire script?
A while loop basically prevents anything underneath it from running, as Lua compiles (runs) the code from top to bottom.
to fix this, you can use a thing called "spawn".
local lighting = game.Workspace.Model local light = lighting.LightPart local timeOutput = game.Lighting:GetMinutesAfterMidnight() local nightStandard = 6 local dayStandard = 18 local num = 2 local function DayNightCycle() while wait(.2) do num = num + 1 game.Lighting:SetMinutesAfterMidnight(num *60) print(game.Lighting.TimeOfDay) end end local function bindToTime() print("binded") end spawn(function() while wait(1) do bindToTime() end end) DayNightCycle()