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

How to make a controllable moving time?

Asked by 4 years ago

I've been trying to figure out how to make a dynamic weather system in my game. I have made attempts at it but the problem always came that I controlled time and weather tweens with static while loops and tweens, which didn't work out well when trying to change the speed of day. I would have to change every wait function to correlate with the right time, which is not intuitive or useful. Optimally I want to be able to change to different times of day, or just change the speed of time, and the right lighting hits at the precise time its meant to, even if I were to move it backwards. This time around I gave the script not only more control over changing the time, but the ability to speed time as I please. It's a step in the right direction but a big problem is showing up.

I am using a while wait loop to change time still, which is not great. I can't control times speed well when i'm waiting for an ingame minute to pass for the script to loop over and reread the updated variables. I tried using a module script with an update method on runService.Heartbeat to move time, but it came out buggy and uneven. I don't know what else I can do, as renderStepped is only for clients. Is there a way to make time pass smoothly on heartbeat, or is there another way I can make time pass that gives me enough control?

function loop:update(dt)
    if enabled.Value then
        print("Time: "..inittime.Value)
        inittime.Value = lighting:GetMinutesAfterMidnight()
        lighting:SetMinutesAfterMidnight(inittime.Value + (dt * multiplier.Value))

        remotes.send_time:FireAllClients(inittime.Value)
    end
end

Answer this question