Why does a simple tween lag so much?

simple tweening on ONE block(not a mesh) spikes my ping to around 300
My code:

	local TweenService = game:GetService("TweenService")
	local TI = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
	local T2 = TweenInfo.new(.2,Enum.EasingStyle.Linear,Enum.EasingDirection.In,0,false,0)
	local properties = {
		Size = Vector3.new(4,5,0.05) -- expanding
	}

	local properties2 = {
		Size = Vector3.new(.1,.1,.1) -- shrinking
	}

	local Tween = TweenService:Create(i,TI,properties)
	Tween:Play()

	wait(2)
	local Tween2 = TweenService:Create(i,T2,properties2)
	Tween2:Play()

Before, my shrinking properties’ value was set to (0,0,0) and i had thought that was what was making it laggy because in my mind, it was trying to round it to the nearest value of 0, which would be like 0.1111111e or something like that, and that would make sense, but after setting it to (.1,.1,.1), i found out that wasnt what was making it lag, so at this point im a bit confused. I even made a debounce to make sure it wasn’t tweening it 1000 times at the same time but no luck.
I also made my tweens faster to compensate, but it’s still there. I even replicated the tween to each client through a remote event, and it still lags as much. Not only does it lag with tweening size, it has the same effect for eg. brickcolor, position, and transparency. I tried these both on my acer nitro 5 laptop which has modern day hardware, AND a new desktop which I had recently just built. It has an RTX something like 2070 so it cannot be a hardware issue.

1 Like

Is this the full code? or is there something else you cut out.

yes, I did cut out everything else that was irrelevant, nothing to do with the tweening. Also, I replaced the part I was tweening with ‘i’

Are there any loops in your code, and are you sure its the tween thats lagging you?

mhm it’s gotta be the tweening. I expanded the time in seconds of the tween to ten seconds to make sure, and for ten seconds I lagged so hard lol

I believe that you have a for loop in your script. That is probably the issue, can we see that part of the script?

Yeah sure, I do have a for loop, but it’s for getting the players inside a touched block which is far under and out of the tweening block

Your code for the tweening looks fine and should work, Its probably something else like a loop. Check for some more possible reasons your lagging. Anything that runs more than once could be it.

1 Like
i.Touched:Connect(function(hit)

		local humanoid = hit.Parent:FindFirstChild("Humanoid")
		if hit.Parent.Name == Player.Name then
			event:FireClient(Player)


			if Player.Character.Torso.Transparency ~= 1 and debounce == false then
				debounce = true

				for i,v in pairs(Player.Character:GetDescendants()) do
					if v:IsA("Part") or v:IsA("MeshPart") then
						v.Transparency = 1
						if v:FindFirstChild("Face") then
							v.Face.Transparency = 1

						end
						if v:FindFirstChild("face") then
							v.face.Transparency = 1
						end
					end
				end

When a player touches a part, the touched event often first 20-30 times. Both legs constantly moving up and down, causes the event to fire a lot. You are probably firing the server at least 20 times in a split second and using the server to tween it 20 times. Try adding debounces on the client side.

Not necessarily it needs to touch from physics not animations.

I have a debounce on the client already though

Are you 201% sure its the tween?

i can take a clip of it to show when it does indeed lag

2 Likes

Oh you’re right, sorry I missed that.

Desktop 2021.01.07 - 19.55.28.02.DVR_Trim ,

dont mind my click clack keyboard kek

its worse if im tweening size though so uh yikes

So it could be the amount of time it takes for the tween to happen, maybe increase that value
or it could be the function that makes the tween begin

yeah but remember I already tried that, i increased the time to 10 seconds and I lagged for a continuous 10 seconds.