Tweening every part in a model causes lag

Hello! This is my first post on the devforum; I’ve finally run into an issue I just can’t seem to solve.
What I’m trying to accomplish is tweening the transparency of every part in a model. I don’t think this would inherently cause lag.
(I am creating a stand from Jojo’s Bizarre Adventure)

This is what happens when I summon the stand
https://gyazo.com/82ef5b583854ac00977c056b051aa74f
While the lag isn’t very noticeable, near the end of the gif you can see that the microprofiler is slowing down when I summon and desummon the stand. There are minor spikes in activity aswell.

When I use an fps unlocker, the difference is more noticable.
https://gyazo.com/ac905e32a83b598ded56c1d691a321b5

While the lag isn’t very extreme, sometimes it does just appear to get worse on different days. What’s interesting is that the lag does not occur in roblox studio.

I know there must be a way to achieve this and have zero lag. This is the stand summon effect from Your Bizarre Adventure, also with an fps unlocker.
https://gyazo.com/c2d45fd06ac1e9029c0d1244de5c8183
(The gif lowers the framerate of it, but take my word for it; there is a lot less lag than what I’m experiencing)

This is a snippet of the server script that fires when the player presses Q.
Important to note, the “Cel” I refer to in the script is an aura around the stand and the player. It is just a roblox character model with inverted faces.

function summon(StarPlatinum,player,value)
	--send the stand to tween transparency on, the info (time), and the value to tween to
	
game.ReplicatedStorage.ClientSideEffects:WaitForChild("SummonStandTween"):FireAllClients(StarPlatinum,.2,value)
	game.ReplicatedStorage.ClientSideEffects:WaitForChild("StandAura"):FireAllClients(StarPlatinum,.4,value)
	game.ReplicatedStorage.ClientSideEffects:WaitForChild("StandAura"):FireAllClients(player.Character,.2,value)

	wait(.3)
	for i,v in pairs(StarPlatinum:GetChildren()) do
		if v:IsA("MeshPart") or v:IsA("BasePart") then
			if not v:FindFirstChild("AuraOff") then
			if v.Name ~= "HumanoidRootPart" then
				if v.Transparency ~= value then

					v.Transparency = value
					
				end
			end
			end
			end
	end
	
	for i,v in pairs(StarPlatinum.Cel:GetChildren()) do
		if v:IsA("MeshPart") or v:IsA("BasePart") then
			if not v:FindFirstChild("AuraOff") then
			if v.Name ~= "HumanoidRootPart" then
				if v.Transparency ~= value then

					v.Transparency = value
					
				end
			end
		end
		end
		end
	
	for i,v in pairs(player.Character.Cel:GetChildren()) do
		if v:IsA("MeshPart") or v:IsA("BasePart") then
			if not v:FindFirstChild("AuraOff") then
			if v.Name ~= "HumanoidRootPart" then
				if v.Transparency ~= value then

					v.Transparency = value

				end
			end
		end
	end
	end
end

The reason I wait 3 seconds in the middle of the function is to only set the stand to visible on the server when the tween is finished for every player.
I achieved this effect from the server’s point of view. The server is not handling these tweens.
https://gyazo.com/f38a7e1dd60fe238710380ab483241cb

These are the client sided functions that fire from the :FireAllClients() above, which I suspect carry the problem.

local remoteevent = game.ReplicatedStorage.ClientSideEffects:WaitForChild("SummonStandTween")

remoteevent.OnClientEvent:Connect(function(stand,info,transparencyv)
	
	local Info = TweenInfo.new(info)
	local tweens = {}
	for i,v in ipairs(stand:GetChildren()) do
		if v:IsA("MeshPart") or v:IsA("BasePart") then
			if not v:FindFirstChild("AuraOff") then
			if v.Name ~= "HumanoidRootPart" then
			if v.Transparency ~= transparencyv then
	
					local Tween = game:GetService("TweenService"):Create(v,Info,{Transparency=transparencyv})	
						table.insert(tweens,Tween)
						
				end
			end
		end
	end
end
	
	for i,v in ipairs(tweens) do
		v:Play()
	end
	wait(2)
	table.clear(tweens)
end)


local remoteevent2 = game.ReplicatedStorage.ClientSideEffects:WaitForChild("StandAura")

remoteevent2.OnClientEvent:Connect(function(stand,info,transparencyv)
	
	local Info = TweenInfo.new(info)
	local tweens = {}
print(stand.Name)
	for i,v in ipairs(stand.Cel:GetChildren()) do
		if v:IsA("MeshPart") or v:IsA("BasePart") then
			if not v:FindFirstChild("AuraOff") then
		
				if v.Transparency ~= transparencyv then
	
							local Tween = game:GetService("TweenService"):Create(v,Info,{Transparency=transparencyv})
						table.insert(tweens,Tween)

			end
		end
	end
end
	
	for i,v in ipairs(tweens) do
		v:Play()
	end
	wait(2)
	table.clear(tweens)
end)

Things I’ve attempted to change include Using :GetDescendants(), I’ve used coroutines to play the tween inside of the loop, and I’ve even replaced the model with a blank character model just to make sure the model is not at fault here.
This is a gif of that test, with an fps unlocker
https://gyazo.com/e43ed1c317fb9f7a15b01fb5a27d022f
(Don’t mind the messed up aura, it does not effect the performance anymore than it usually does)

The parts of the stand model are created from meshes colored with a texture, which does reduce part count.

I think a contributor could be the method of getting the parts, because I am looping through GetChildren and adding everything to a table. To me, the amount of lag produced from this method doesn’t seem feasible.
When I remove the tweens completely, lag is nonexistent. I want to know if there is anything I can do to have the tweens and also have no lag. Or is this just an unavoidable issue when I am tweening this many parts. Any help or thoughts are appreciated, Thanks for reading!

-I am not entirely sure how to view specific causes in the microprofiler, if you would like to see that information just ask.

No idea.

I don’t notice the lag myself, but the reason you are getting no lag in Studio, is that your computer is acting as both the server and the client…
But in Play, every time that you call a remote, that is a communication to the Server, which is in Alaska, then back to your town, so do the entire loop on the client.

Also, use a larger Tween increment, and add a wait(?) to slow the effect, and to allow the computer to go away and do other stuff during the tween.

GL
(I have no idea what you are even doing…)

1 Like

Thanks for the reply! The post is a bit convoluted, so I can’t blame you for not quite understanding. I simply want the model to go behind me and go from invisible to visible. The tween responsible for transparency seems to cause lag.
The loop for detecting parts in the model and playing the tween is already on the client, so there isn’t anything I can do there unfortunately. However, the difference between in studio and in actual roblox could tell me some more information on what exactly is causing lag.

Yeah the only time that I notice lag or stutters is when I am in a very large loop, without a wait(), so I just add a wait() every100 or so iterations…

1 Like

You could try welding all the parts in a model to some random part in the model, then tween that random part you chose, and when the tween is over, unweld all the parts.

1 Like

Just to clarify, I don’t need to change the position of the model. I should have stated that. I am playing an animation for that part of it. It is just the transparency aspect of it that I need help getting rid of lag with. Thanks for the reply!

Wow, does changing the transparency of a RootPart, change the Transparency of the entire Model? That is brilliant.

1 Like

That sure would make things a lot easier if there was a setting for that.

I’m sorry for not seeing that, I don’t have any ideas for your issue in particular.

1 Like

I wish it did, but apparently I can’t read!

1 Like

He should try anyway. What does he have to lose…

Or, put a bunch of Prints. Maybe you re doing a lot of back and forths to the client that you don’t know about…

2 Likes

I added a print statement when it receives the remote event on the client, and it does only receive it once. So it could be related to the number of parts, 31, of which I’m not sure if there’s anything I can do to help other than deleting them.

31 does not seem like much. I can make an entire map on a globe consisting of 4000 Hexs, before the first Player even arrives… I’m pretty sure.

1 Like

Yeah, it really doesn’t seem like a lot of parts. Though I forgot to include the aura and the player aura along with it, its still less than 100 parts. Not to mention there is a slight delay between different aura tweens playing, so it’s not like all 100 tweens are playing at the same time.

You will find it.

It lags, maybe, because you’re taking the lords name in vain. (I’m kidding)…

Don’t know if this helps, but:
I turn and fire a Player’s cannon on the Server, but noticed a bit of lag, so I started turning the cannon on the Client before the Server Remote, then let the Server finish the turn and fire.

Got the idea from Roblox’s Laggy Cannons tutorial… Maybe go there…

1 Like