Getting same time waiting as "tween.Completed:Wait()"

Hello, I’ve ran in this problem. My game has 300+ tweens playing on the client and it lags a lot (only when the parts go fast and I’m not sure why),so I’m trying to optimize all this tweens without playing them, but with just teleporting the part after the Time value (this when the part is too far) so I’ve tried using task.wait(Time) but it doesnt wait the same as Tween.Completed:Wait(), and I’m stuck here.

there is an example of what the script should be

local dis = (movingPart.p-target.p).magnitude
local Time = dis/speed

local HumDis = (movingPart.p-RootPart.p).Magnitude

if HumDis < 200 then
   local tween = TweenService:Create( --something-- ) --here the time it takes is the same as the Time value



   task.wait(Time) --here it doesnt wait the same as the Completed:Wait()
   movingPart.p = target.p


I’m not entirely sure what you are trying to achieve, however, Tween.Completed:Wait() will yield (or hold) the program until the tween itself is complete. This can range from instant to full on minutes, depending on the length of the tween.

Whereas task.wait() will only yield the program for a set amount of time that you give it.

I hope this helps!

1 Like

Task.wait is fast than wait. Also, the tween.Completed:Wait() yields until the tween is over then does the wait() method.

the Time variable is the same for the tween and the wait, but since there are a lot of tweens (or maybe just the memory usage) slow down the task.wait(), so I was just need to find a way on how to wait the same as the tween takes

When dealing with that many tweens, it’s best to set them up to run the tween and that’s about it.
Asking for more out each one of them compounds cycle time. Most of this here could be done in a generic script linked to all of them that set off the tween or just moved them itself as with your else statement. Also again with that many tweens you can’t get to complicated with what that tween is doing.

Example: I have a game that has 300 to 500 coins in a maze. At first I had the coins spinning and bobbing up and down. It looked great but in the end lagged really bad with many coins out. I went back and just made them spin with out the bobbing and now they work fine with no more lag.
I was just asking too much of the original tween for that to be covered smoothly.

1 Like

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