Still have questions? Join our Discord server and get real time help.
Log in to vote

Faster or more independent loop times?

Asked by 2 years ago

Since i started using renderstepped to wait, it seemed nice, but i wasn't aware that it runs on the clients "heartbeat" aka they're fps. Im trying to animate guns, and run loops as fast as possible, but renderstepped seems to kill that when slower pc's play the game. So i was wondering how to use tick() or anything else that can be used for a loop quicker then wait()

1 answer

Log in to vote
Answered by
tkcmdr 341 Moderation Voter
2 years ago

Hey Abstract_Life!

First of all, we need to look at the RunService Wiki page. Upon doing so, we see Heartbeat and RenderStepped, both of which are dependent upon the frame rate. We do not want that. There is one more event, however, called Stepped. This is not dependent upon the frame rate, and runs roughly thirty times per second on a consistent basis.

Here is a quick mock-up of how you can use it effectively (without wait!):

local LastUpdate    = 0;        -- Time of the last update
local WaitTime      = .01;  -- The amount of time between updates

local function Update()
    -- We subtract the current time from the last update to find the amount of time between tht two. If it is more than WaitTime, we go to town (er, into the if block.)
    if ((tick() - LastUpdate) > WaitTime) then
        LastUpdate = tick();    -- Set LastUpdate to the current time. VERY important.

        -- Do the animation updates and stuff


Hope this helps. Merry Christmas, and best of luck with your FPS!

Warm regards, tkcmdr


Answer this question