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
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).