Hello! I have a small bug in my code and I’m not sure how to fix it, any ideas?
The problem I’m having is that when the player reset, the time stops, but it should continue regardless of whether the player resets. Should I handle it on the server or how can I resolve it?
what i want
I would like the time to be the same for everyone and always be continuously advancing.
Currently, the LocalScript is located at:
Localscript:
-- Get references to objects
local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = playerGui:WaitForChild("Game_UI")
local textLabel = screenGui:WaitForChild("Timer_UI_CurrentTime")
-- Set the clock speed
local clockSpeed = 1
while true do
wait(1) -- Wait for one second
local currentTime = game.Lighting.ClockTime
local newTime = currentTime + (1 * clockSpeed) / 60 -- Increase time by 1 minute
game.Lighting.ClockTime = newTime
local hour = math.floor(newTime)
local minute = math.floor((newTime % 1) * 60)
-- Format the time to be displayed as "hh:mm"
local formattedTime = string.format("%02d:%02d", hour, minute)
-- Update the TextLabel text
textLabel.Text = "Time: " .. formattedTime
end