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

How to make this run slower?

What I'm trying to do is get the game time to increase, but it runs really fast, and I'm unsure of how to make it slower.

local start,starthour = tick(),game.Lighting:GetMinutesAfterMidnight()
game:service('RunService').Stepped:connect(function()
local secs = tick()-start
game.Lighting:SetMinutesAfterMidnight(secs+starthour)
end)

1 comment

0

Always use deltas! Keep track of how much time is passing between things where you care about how fast things go! The Stepped event should tell you how much time passed since the last time.

1 answer

✓ Accepted answer
local start, starthour = tick(), game.Lighting:GetMinutesAfterMidnight()

-- Tweak this to control the speed
local speedModifier = 0.5
-- I recommend keeping serperate variable for day/night time
local gameTime = 0 

-- When it comes to Stepped and RenderStepped it's recommended to use the event in setup like this, otherwise the 'connect' function will create new Lua threads every time event is called, which is not nice
while true do
	-- If you know the time that has passed since the last function call, you can easily change the 'virtual time'(which would be the gameTime variable)
	local time, delta = game:service('RunService').Stepped:wait()

	-- Without the speed modifier, gameTime would show actual passed seconds since script began, but now you can alter how quickly this time will pass
	gameTime = gameTime + delta * speedModifier

	game.Lighting:SetMinutesAfterMidnight( gameTime + starthour)
end

Edit: Forgot that stepped already provides delta(thank you BlueTaslem). Updated script

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