I have a system that spawns in a section of the map with lots of tweens. It works right now, but I am worried that later if I make a larger section with a hundred to a thousand parts, it would cause a lot of lag with all the tweens happening.
This is the way I want it to spawn in like:
The way I scripted it is first it makes all the parts invisible, then parents it to the workspace from replicated storage, and then creates and plays a tween for every part to make it visible.
I was thinking maybe instead of lots of tweens, I could do one large RunService function, but I don’t know effective it would be from preventing lag. Does anyone have any ideas on how I can make probably a couple hundred parts tween without the game lagging?
I like how each object has a slight delay before beginning to tween the next. It ensures the client isn’t overloaded by too many parts.
My personal idea on how you could potentially reduce lag is a sort of queue system.
You can set a cap, let’s say 30 parts, and you can only have up to 30 parts tweening at any point in time. Each tween can then wait until X (amount of tweens tweening) is <= 30, and then run the next tween in queue when that statement is true.
Assuming each tween takes 0.5s, and each new tween has a delay of 0.05s, that means your cap should be… 25 tweens.
In any point in time, you’ll have about T (time for each tween) divided by D (delay for each tween), which should get you A, the max amount of tweens in a moment in time.
T/D = A
In the rough example case, that means 0.5/0.05, which results to 20. I added a 25% additional cap just to cover any lag between tweens starting or ending, to get to 25.
Honestly speaking though, It seems that whatever you’ve done will work out perfectly fine in the long run!
My Queue suggestion won’t have too much of an impact, but it’s worth having it noted down, in case there are potential lag issues or you’d simply like to cap the amount of tweens.