How do I do this

if I had a part and moved it in a repeat loop using task.wait() , how could I make it move faster but still being smooth using task.wait(nothing)???

i’m confused how toavheive this making it smooth. it’s like in tweening you do time of tween and it moves slow or fast. how???

nvm I’m gonna do something completely different way

nvm how do I do this like how does fastcast do it

Use the modulo operator so it only waits once for multiple loop cycles:

local counter = 0
while true do --any loop
	--your loop code
	counter += 1
	counter %= 10 --yield the loop per 10 cycles
	if counter == 0 then task.wait() end --no input means least possible wait time
end

If the modulo number(in this case 10) is low, we waste time waiting. If the modulo number is high, the script may become laggy(especially if it performs costly operations). So you need to adjust the number in accordance to your needs.

Also keep in mind that this code is useless when ran inside event connections, that’s because event connections don’t yield code like loops do. Basically waiting in one iteration won’t stop the event and the code within it from firing again during said wait. Unless of course you add your own custom mechanisms for that(using global variables and such).

1 Like

task.wait(lower number)
maybe use tween … total control over speed, always smooth.

1 Like

look into how frame rates and how deltaTime works, you’ll probably end up tying whatever you’re doing to RunService.Heartbeat or RunService.Stepped