Preventing visual & other problems with high / low fps

Currently with how my system is now, it can cause unintended issues in behavior, things being genuinely faster, visuals being too quick to see or moves ending in a flash or the exact opposite if they have say 5fps. I’ve tried using Heartbeat, but to no avail, I know you can get it to make this stuff work identical to what it’d be with 60fps though. Ideas/Help is appreciated.


function swait(n) --Local script, used for abilities and such
	if not n then game:GetService("RunService").RenderStepped:wait() else local t = time()
		repeat game:GetService("RunService").RenderStepped:wait() until time()-t >= n/60
	end
end

---

local function swait(n) --Used in module for *numerous* visual effects
	for i = 1, (n or 1) do 
	game:GetService("RunService").RenderStepped:wait()
	end
	end

The proper solution is to base your animations around time that has actually passed.

With the introduction of the Maximum Framerate setting, this is even more important:

Luckily, they have generously provided examples of what and what not to do:

It looks like your code is currently doing the first thing, where you’re waiting for a fixed amount of time to pass and then updating the position based on that fixed amount of time.
Instead of:

while true do
  swait()
  newValue += 1/60
end

You should do:

NUMS_PER_SECOND = 60
while true do
  timeElapsedSecs = time.wait()
  newValue += timeElapsedSecs * NUMS_PER_SECOND
end
1 Like