Hey y’all, after a break from scripting I decided today to return to working on my day and night cycle, but have now run into some behavior I don’t quite understand. In my local script, I have lines of code checking wether or not a boolean from my module script is set to true or false respectively. When lockTime is true, the cycle is supposed to pause by disconnecting its heartbeat. When lockTime is false, its supposed to return to working. But for some reason, it isnt actually registering the boolean as true or false. Down below is the code from both scripts, any and all help figuring this out will be greatly appreciated <3
local Lighting = game:GetService("Lighting")
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local globalVariables = require(ReplicatedStorage.Modules.Data.globalVariables)
local currentTimeofDay = ReplicatedStorage.Values.currentTimeofDay
local function tween(l, p)
TweenService:Create(Lighting, TweenInfo.new(l, Enum.EasingStyle.Linear, Enum.EasingDirection.In), p):Play()
end
--Change the time of day
local function changeTimeofDay()
globalVariables.currentTime += 1
if globalVariables.currentTime > #globalVariables.timesofDay then
globalVariables.currentTime = 1
end
currentTimeofDay.Value = globalVariables.timesofDay[globalVariables.currentTime]
print(globalVariables.timesofDay[globalVariables.currentTime])
end
--Tween sky colors
local tweenSkyCo = coroutine.create(function()
end)
--Change the time of day
local changeTimeCo = coroutine.create(function()
if (Lighting.ClockTime >= 6 and Lighting.ClockTime < 6.5) then
changeTimeofDay()
elseif (Lighting.ClockTime >= 6.5 and Lighting.ClockTime < 7) then
changeTimeofDay()
elseif (Lighting.ClockTime >= 12 and Lighting.ClockTime < 12.5) then
changeTimeofDay()
elseif (Lighting.ClockTime >= 17 and Lighting.ClockTime < 17.5) then
changeTimeofDay()
elseif (Lighting.ClockTime >= 17.5 and Lighting.ClockTime < 18) then
changeTimeofDay()
elseif (Lighting.ClockTime >= 18 and Lighting.ClockTime < 18.2) then
changeTimeofDay()
end
end)
--The visual time of day
local clockTime = RunService.Heartbeat:Connect(function()
Lighting.ClockTime = (workspace:GetServerTimeNow() / 960) % 24
end)
--Pause the current time for singleplayer content
if globalVariables.lockTime == true then
coroutine.yield(changeTimeCo)
clockTime:Disconnect()
elseif globalVariables.lockTime == false then
coroutine.resume(changeTimeCo)
clockTime = RunService.Heartbeat:Connect(function()
Lighting.ClockTime = (workspace:GetServerTimeNow() / 960) % 24
end)
end
local globalVariables = {}
--Time
globalVariables.timesofDay = {"Dawn", "Morning", "Afternoon", "Evening", "Dusk", "Night"}
globalVariables.currentTime = 1
globalVariables.lockTime = true
return globalVariables
