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.