Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make this run slower?

Asked by 8 years ago

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)
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. BlueTaslem 18071 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago
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

Ad

Answer this question