Is there a non fps dependant version of task.wait()?

Currently, I’m using task.wait with a while loop to create a shaking effect for my UI. This effect however, can be longer/faster than intended depending on the player’s FPS. How can I fix this?

Code:

local OriginalPosition = Interface.HUD.MVP.Position

for i = 1, 80, 1 do
	Interface.HUD.MVP.Position = OriginalPosition + UDim2.new((Random.new():NextInteger(-2, 2) / 500) * (i / 80 * 2), 0, (Random.new():NextInteger(-2, 2) / 500)  * (i / 80 * 2), 0)

	task.wait(0.01)
end

for what i know of there is no non-fps depentand alternative. but you could use

game:GetService("RunService").RenderStepped

(no idea if i spelt it right) and connect it to a function and use the “DeltaTime” to calculate how much to move the ui (seems like you’re working with ui). Using this method will require a rework of your script so your choice if you wanna use it or not

ok i just tried it but it gives me the same result, i dont think itll work since renderstepped is also reliant on the players fps

yes, renderstepped also relies on fps. but it has an input called “DeltaTime” which you can use to calculate how much the ui should move depending on the time between frames (DeltaTime = time between frames).

2 Likes

i just realised what u were talking abt, it works tysm

task.wait() also returns wait time. In case of waiting less than frame, it will produce similar results as RenderStepped.

local Waited = task.wait()
1 Like

this post has already been solved but ty anyway

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.