How to make Tween Script not lag my game?

I was making my tweening script for an obby and it worked but the problem was my game became laggy. When I used multi lined comments on my tween script to make it stop, the game turned back to normal so I believe I have too many scripts or something is wrong with my tween script. I have one more script that tweens my GUI but it didn’t lag my game. My tween script that lags my game is shown below. I would really appreciate it if someone helped me and thank you in advance.

local part = script.Parent
local TweenService = game:GetService("TweenService")

local Info = TweenInfo.new(
	1,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	-1,
	true,
	1
)

local Goals = {
	Size = Vector3.new(7.01, 40, 3)
}

local Tween = TweenService:Create(part, Info, Goals)
Tween:Play()

If you are tweening lots of parts on the server then that could make things laggy. If possible move these to be in a local script so that the tweening is happening on each client, that should take away the lag

You might need to put all the parts you want to tween in a folder, or mark them up in some other way.
Then in a local script loop through all of these and start a tween for them all, it should then be smoother and not laggy

If you are tweening really huge numbers of parts you might need to do more optimising (e.g. only actually tweening things that the player is close to/can see)

1 Like

A few suggestions would be.


  • Make the tween/animation clientsided and use a event for the purpose of touching or other interaction
  • Make sure that when you use tweening in a loop to wait till then in-action tween is completed by using Tween.Completed:Wait()
2 Likes

I made a tutorial on how to improve game performance here: Pointers to reduce lag in your game

The tween shouldn’t lag your game but if it does, it might be because you are tweening a huge object or that something in your tween isn’t working right.

Directly answering, use LocalScript for that since it runs on Local not Server so it doesn’t lag?

1 Like