I’m trying to make my script add one to an IntValue so I can create a working day system in my game. For some reason, whenever the ClockTime hits 0, it doesn’t add one like it’s meant to. I’ve tried adding a loop, using a print value, and a few other things, but none have worked.
local lighting = game:GetService("Lighting")
local replicatedStorage = game:GetService("ReplicatedStorage")
local event = replicatedStorage:findFirstChild("Time")
while wait(.9) do
local hours = math.floor(lighting:GetMinutesAfterMidnight() / 60)
local suffix = "AM"
local minutes = lighting:GetMinutesAfterMidnight() - (hours * 60)
if hours > 11 then
hours = hours - 12
suffix = "PM"
end
if hours == 0 then
hours = 12
end
if minutes < 10 then
minutes = "0" .. minutes
end
local text = hours .. ":" .. minutes .. " " .. suffix
event:FireAllClients(text)
lighting:SetMinutesAfterMidnight(lighting:GetMinutesAfterMidnight() + 1)
end
if game.Lighting.ClockTime == 0 then
local val = game.Lighting.DotW
for i = 1,10 do
val.Value = val.Value + 1
print(val.Value)
end
end
I’m not sure how your game works but the problem might be that the ClockTime is a decimal like 0.01 instead of 0 as the for loop executes only if it’s exactly 0.
NumberValues are just IntValues except they store floats instead of integers. Why would using a NumberValue be helpful if OP wants to make a significant time jump? Nothing stops OP from doing IntValue.Value = 15 on a whim.
I believe the problem stems from the fact that the if statement checking for whether ClockTime is 0 or not only runs once, not every time ClockTime hits 0 at any point.
Try:
lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
if lighting.ClockTime == 0 then
local val = game.Lighting.DotW
for i = 1,10 do
val.Value = val.Value + 1
print(val.Value)
end
end
end)
The entire space above the section that adds one is what changes the time of day.
local lighting = game:GetService("Lighting")
local replicatedStorage = game:GetService("ReplicatedStorage")
local event = replicatedStorage:findFirstChild("Time")
while wait(.9) do
local hours = math.floor(lighting:GetMinutesAfterMidnight() / 60)
local suffix = "AM"
local minutes = lighting:GetMinutesAfterMidnight() - (hours * 60)
if hours > 11 then
hours = hours - 12
suffix = "PM"
end
if hours == 0 then
hours = 12
end
if minutes < 10 then
minutes = "0" .. minutes
end
local text = hours .. ":" .. minutes .. " " .. suffix
event:FireAllClients(text)
lighting:SetMinutesAfterMidnight(lighting:GetMinutesAfterMidnight() + 1)
end