Animations or TweenService

Hey!
In my game, a lot of parts fall from the sky.
Its just a fun little part of the game that can be toggled in the games settings, but Ive experienced a LOT of lag with this.

Currently, the parts (called Bricks) fall from the sky using a tween with the “Bounce” EasingStyle, and I believe that might be causing the lag.

Should I swap to custom animations for better performance?

Oh and I forgot to mention that there are about 200 bricks falling per second. How would I go about loading the animations? Wouldnt it also be laggy to load in hundreds of animations seperately?

3 Likes

The bounce tween is not what is causing you lag

It’s likely either part creation and/or moving the parts (from TweenService or .CFrame)

If you are using :PivotTo(), :PivotTo() is particularly laggy. I can explain how to move a model using .CFrame or BulkMoveTo if that is the case

If you are able to provide a micro profiler dump, that would be great, as we’d be able to tell you exactly what is causing the lag

At the end of this page, it talks about micro profiler dumps

1 Like

Alright, also the part creation cant be the biggest issue since the game runs smoothly if the animations are disabled.
microprofile-20250304-133504.html (9.0 MB)

The dump makes it look like the cloning of parts is the issue, but as Ive stated above, it works just fine if the animations are disabled

Try using a different easing style.

Sometimes when I use easing styles like bounce, cubic, etc. they make the things I’m tweening look like lag

but most likely, it’s the 200 bricks falling per second. that cannot be good for performance, and my pc would lag with even 20 probably XD

Maybe try lowering the parts falling per second? that might work also.

No, thats not possible since the falling bricks are the main part of the game.
The tweening doesnt look choppy or anything, the game just gets reduced to 0.5 FPS.

Also, I chose Bounce because it looks realistic. Bricks just gliding down linearly would probably look… questionable.

1 Like

i dont know if there would really be a solution to this problem then…

Are your scripts optimized? This would also help with reducing lag.
if there is a lot of

while wait() do

loops then try to swap those for something else to help performance.

1 Like

this is the relevant code

local player = game:GetService("Players").LocalPlayer
local ar: RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("ClientFXEvents"):WaitForChild("AnimateBuilders")
local bricksFolder = game:GetService("Workspace"):WaitForChild("ClientBricks")
local ts = game:GetService("TweenService")
local toggle: BoolValue = player:WaitForChild("Settings"):WaitForChild("BrickAnimations")
local random = math.random
local AnimateBulldozersEvent = game:GetService("ReplicatedStorage"):WaitForChild("ClientFXEvents"):WaitForChild("AnimateBulldozers")
local points = game:GetService("Workspace"):WaitForChild("BrickSpawn1"):WaitForChild("Builders"):WaitForChild("Points")
local RunService = game:GetService("RunService")
local BulldozerScale = game:GetService("ReplicatedStorage"):WaitForChild("Bulldozer"):GetScale()

-- Load Tweens --

local FallTweenInfo = TweenInfo.new(1.25, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out)
local TransTweenInfo = TweenInfo.new(1, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out)
local function AnimateChild(child:Instance)

	child.Transparency = 1

    child.Orientation = Vector3.new(0, random(0, 360), 0)
	if child.Name == "BrickD" or child.Name == "BrickE" then
		child.Orientation = Vector3.new(random(-25, 55), random(0, 45), random(-25, 65))
	end	

	child.Position = Vector3.new(child.Position.X, child.Position.Y + 40, child.Position.Z)

	local FallTween = ts:Create(child, FallTweenInfo, {Position = child.Position - Vector3.new(0, 40, 0)})
	local TransTween = ts:Create(child, TransTweenInfo, {Transparency = 0})
	FallTween:Play()
	TransTween:Play()

	task.delay(TransTween.TweenInfo.Time, function()
		TransTween:Destroy()
		FallTween:Destroy()

		if child.Name == "BrickD" or child.Name == "BrickE" then
			child.Position = Vector3.new(child.Position.X, child.Position.Y+2, child.Position.Z)
		end
	end)


	return


end

bricksFolder.ChildAdded:Connect(function(child: Instance)
	if toggle.Value == true then
		do
			local function animate()
				AnimateChild(child)
			end
			
			local Cor = coroutine.create(animate)
			coroutine.resume(Cor)
			
		end
	else
		child.Transparency = 0
	end
end)

first thing I see, is that you are using “WaitForChild()” Way to much so maybe cut those down a bit…

other than that, i see nothing that would be making the game lag.

(i might be blind though.)

1 Like

Well im only using it at the start to load all of the global variables.
It only runs once there so it shouldnt matter at all

I use it since (i forgot to mention this) the script is on the client

2 Likes

You’ve stated that you were using tween service? Is that what you mean by animation here?

2 Likes

I can access the dum just fine? Maybe try using a browser instead of… uh… discord? The code is already up there

I’m using a documents app on my phone, I don’t think anything else will allow me to open the html file

The message seems to be about how it was saved. Unless it does some weird conversion when I saved it, I don’t think my documents app is the issue

If you download the html you posted, it works for you?

1 Like

yep it works just fine for me, even if I download it again

1 Like

i dont know how to work the microprofiler very well, but i took a screenshot of it, if that helps?

(this is from the link he sent, if you were wondering)

2 Likes

That isn’t a relevant part of the micro profiler graph

I have another microprofiler file saved on my phone and that one works, so I think it had to do with how it is being saved in my documents app

2 Likes

Could you try sending the file again, but removing the file extension completely, or making it a .txt?
That way, my phone will have to download the raw thing rather than open it as a webpage and download that…
Sorry for the troubles

1 Like

I don’t think your issue is the tweens since they’re just math. Why can’t you just use the physics engine to make the parts fall?

1 Like

That would lag way more lol
jwkwkalwlw

1 Like

Why do you need 200 parts/s falling?

1 Like