-- LocalScript in StarterPlayer > StarterPlayerScripts, named PracticeCycleVisual.
-- Requires the companion server Script. Visual time only, not gameplay authority.
local Lighting = game:GetService("Lighting")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local config = ReplicatedStorage:WaitForChild("PracticeDayNight", 10)
if not config then warn("PracticeDayNight missing; check the server Script and Output") return end
local warned = false
local function finite(value)
    return type(value) == "number" and value == value and math.abs(value) < math.huge
end
local function updateClock()
    local seconds = config:GetAttribute("CycleSeconds")
    local startHour = config:GetAttribute("StartHour")
    local epoch = config:GetAttribute("Epoch")
    if not finite(seconds) or seconds <= 0 or not finite(startHour)
        or startHour < 0 or startHour >= 24 or not finite(epoch) then
        if not warned then warn("Waiting for valid PracticeDayNight timing attributes") end
        warned = true
        return -- A child can arrive before all its attributes; try on the next frame.
    end
    warned = false
    local elapsed = math.max(0, workspace:GetServerTimeNow() - epoch)
    Lighting.ClockTime = (startHour + (elapsed % seconds) * 24 / seconds) % 24
end
updateClock()
RunService.Heartbeat:Connect(updateClock)
