Unable to make this time cycle work

image
I’ve tried doing this at least 10 times now, and I’m about ready too give up. All I want it to do is add to the in-game time. And when it reaches 14 reset back to 12.

The value stays on 12, however.

Two things to note: I am aware there is no wait() in there. But it’s literally 3:30am and I’m not going to bother fixing it right now.
And 1 is a test value to see if it works quickly. The real value will be lower.

What’s going wrong? I’m just irritated with it now.

Try this maybe?

while wait() do
  if Time == 14 then
     Time = 12
  else
     Time += 1
  end
end

Since your is running on a Condition, once that condition is met, the loop will break

Returning the ClockTime value just returns a number. Try this instead:

local l = game.Lighting

while l.ClockTime <=4 do
l.ClockTime += 1
end

if l.ClockTime == 14 then do
l.ClockTime = 12
end
end

I wrote this in mobile so it might be wrong.

ClockTime is a Number, I’m pretty sure you can manipulate it

(No, youre right:

local Time = game.Lighting

while wait() do
	if Time.ClockTime == 14 then
		Time.ClockTime = 14.1
	else
		Time.ClockTime += 1
	end
		

end

)

1 Like

That’s because you are using ClockTime as the value for the variable name Time. What you are doing is something like this:

local object = { Value = 0 }
local objectValue = object.Value

objectValue += 1

Printing the result of object.Value will still be 0, because objectValue is separate from object.Value all it did was copy the data from it; it should be object.Value += 1 and disregard the objectValue variable. In your case you need to do this:

local parent = script.Parent

while task.wait(0.1) do
	parent.ClockTime += 1
end

Still, this method is not the proper way to create a day-night cycle. There should already be a lot of tutorials on the internet; just search “day and night cycle Roblox.”