Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make time continue to go forward until the value is reached?

Alright so this script is suppose to get the exact Minutes After Midnight (time) and then add +1 until it reaches the ClockTime provided. It comes up with argument one missing or nil, if you can help me, please do. I'd recommend posting it into the answer sheet instead of comments so if your comment helps i can reward you. If you think you have the answer, I attempted to post a post about this earlier, answer this as well with the same post. It's basically the same thing.

lighting = game.Lighting
--Made By MillerrIAm
----------------------------------------
game.ReplicatedStorage.ExtraEvents.TimeEvent.OnServerEvent:Connect(function(player,truetime)
	if truetime == "Day" then
		repeat
		lighting:GetMinutesAfterMidnight(lighting:SetMinutesAfterMidnight() + 1) 
		until
		lighting.ClockTime == 14
		wait(1)
	elseif
		truetime == "Evening" then
		repeat
		lighting:GetMinutesAfterMidnight(lighting:SetMinutesAfterMidnight() + 1) 
		until
		lighting.ClockTime == 18
		wait(1)
	elseif
		truetime == "Night" then
		repeat
		lighting:GetMinutesAfterMidnight(lighting:SetMinutesAfterMidnight() + 1) 
		until
		lighting.ClockTime == 24
		wait(1)
	end
end)

Thank you in advance for the reading and answers!

1 answer

✓ Accepted answer

A few problems I'll highlight before providing a fix.

1.) When you're using repeat you want to put a wait() inside of the repeat function if you're looking for a gradual effect. If you don't then it'll just finish immediately. Instead of the sun setting and rising and all of that over a minute, it'll instead do so over 0.01 seconds kind of deal.

2.) GetMinutesAfterMidnight just checks how many minutes have passed since midnight (similar to game.Lighting.ClockTime but multiplied by 60). So when you write

lighting:GetMinutesAfterMidnight(lighting:SetMinutesAfterMidnight() + 1)

You're essentially checking the time then attempting to set the time whilst checking it. This doesn't work because SetMinutesAfterMidnight() has no argument and GetMinutesAfterMidnight just returns a value.

You want to reverse these two, like this, to achieve what you're trying to accomplish:

repeat
lighting:SetMinutesAfterMidnight(lighting:GetMinutesAfterMidnight()+1)
wait()
until
lighting.ClockTime == 14

Hope this helps

1 comment

This discussion is preserved as it was. New answers, comments, and votes are closed.