So, I am trying to make a JJBA game, and I created a stand summoning script.
I tested the summoning out, but for some reason, the entire game lags whenever I summon it.
Here’s a video:
You might not be able to see the lag very well in the video, but it lags a lot more than what it looks like in the video.
I searched everywhere on YouTube, DevForum, and Google for how to fix it, but I couldn’t find a solution. I tried to change some things like the tween speed and more, but nothing worked.
Here’s the code:
for _, part in pairs(stand:GetChildren()) do
if part:IsA("BasePart") and part ~= standhumRP then
local goal = {}
goal.Transparency = 0
local info = TweenInfo.new(.5)
local tween = TweenService:Create(part,info,goal)
tween:Play()
tween:Destroy()
end
end
local goal = {}
goal.C0 = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame)
goal.C1 = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame * CFrame.new(-3,1,2))
local info = TweenInfo.new(.5)
local tween = TweenService:Create(weld,info,goal)
tween:Play()
tween:Destroy()
else
local stand = char:FindFirstChild("StarPlatinumStand")
if stand then
local controller = stand.PrimaryPart:FindFirstChild("Controller")
if controller then
local standhumRP = stand:FindFirstChild("HumanoidRootPart")
for _, part in pairs(stand:GetChildren()) do
if part:IsA("BasePart") and part ~= standhumRP then
local goal = {}
goal.Transparency = 0
local info = TweenInfo.new(.5)
local tween = TweenService:Create(part,info,goal)
tween:Play()
tween:Destroy()
end
end
local goal = {}
goal.C0 = controller.Part0.CFrame:ToObjectSpace(controller.Part1.CFrame)
goal.C1 = controller.Part0.CFrame:ToObjectSpace(controller.Part1.CFrame * CFrame.new(0,0,0))
local info = TweenInfo.new(.5)
local tween = TweenService:Create(controller,info,goal)
tween:Play()
tween:Destroy()
tween.Completed:Connect(function()
stand:Destroy()
end)
end
end
end
end)
I don’t think it’s cause of my CPU, since my current computer is not old at all, and I cleaned it a couple days ago. Maybe it could be cause of the server performance, but I’m not sure how to fix that…
See those sudden spiky parts? That’s where you’re cpu has to take so many process to make it look good. Now press Ctrl/Cmd + Shift + P while hovering you’re mouse to that spike part to see what’s going on.
When its lagging, hit Ctrl+P and it’ll show a full breakdown of the frame. Those ones that reach the top of the bar are the long frames causing the lag. Once you’ve paused it with Ctrl+P it’ll show all the tasks in that frame with labels so you can see what part of the frame took a while.
It’s because the stand is most likely laggy. I had that issue and when I removed the stand it fixed, I recommend reducing the parts. Also the script shouldn’t be a issue because redplys has code similar to yours with no lag.
How many children are inside of the stand? Essentially, how many Tweens are actually being created and played at once here?
It looks like the render step is taking most of the time, which may be a direct result of the tweens, but it could be a result of additional effects if you have any.
Have you considered using Motor6D joints or even the built-in animations system at all? I’d be curious to know if that’s a lot more performant for the same number of parts, textures and any effects.
You don’t necessarily need to remove parts, I was just asking how many there currently are as I notice your code creates a tween for each individual child. I did just realise that was for transparency not positioning though - apologies for misreading it initially.
Try cutting out certain things, like the transparency tweens, to see if you can identify whether the positioning is the issue or the transparency is the issue. Once you’ve narrowed down which one is causing the greater impact, you can then plan your next steps.
It seems like it is both the position, and the transparency. They deal the same exact lag impact, I tried to make the second tween use transparency and the first tween use position. Both had the exact same lag. Even in the microprofiler.
local rp = game:GetService("ReplicatedStorage")
local summon = rp:WaitForChild("Summon")
local TweenService = game:GetService("TweenService")
summon.OnServerEvent:Connect(function(player,isActive)
local char = player.Character
local hum = char.Humanoid
local humRP = char.HumanoidRootPart
if isActive then
local stand = script:WaitForChild("StarPlatinumStand"):Clone()
for _, part in pairs(stand:GetChildren()) do
if part:IsA("BasePart") then
part.Transparency = 1
end
end
stand.Parent = char
stand.PrimaryPart.CFrame = humRP.CFrame
local weld = Instance.new("ManualWeld")
weld.Name = "Controller"
weld.Part0 = stand.PrimaryPart
weld.Part1 = humRP
weld.C0 = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame)
weld.Parent = weld.Part0
local animControl = stand:FindFirstChild("AnimControl")
local standhumRP = stand:FindFirstChild("HumanoidRootPart")
local idle = animControl:LoadAnimation(script.Idle)
idle:Play()
for _, part in pairs(stand:GetChildren()) do
if part:IsA("BasePart") and part ~= standhumRP then
local goal1 = {}
goal1.Transparency = 0
local info = TweenInfo.new(.3)
local tween1 = TweenService:Create(part,info,goal1)
tween1:Play()
tween1:Destroy()
end
end
local goal2 = {}
goal2.C0 = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame)
goal2.C1 = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame * CFrame.new(-3,1,2))
local info = TweenInfo.new(.3)
local tween2 = TweenService:Create(weld,info,goal2)
tween2:Play()
tween2:Destroy()
else
local stand = char:FindFirstChild("StarPlatinumStand")
if stand then
local controller = stand.PrimaryPart:FindFirstChild("Controller")
if controller then
local standhumRP = stand:FindFirstChild("HumanoidRootPart")
for _, part in pairs(stand:GetChildren()) do
if part:IsA("BasePart") and part ~= standhumRP then
local goal3 = {}
goal3.Transparency = 0
local info = TweenInfo.new(.3)
local tween3 = TweenService:Create(part,info,goal3)
tween3:Play()
tween3:Destroy()
end
end
for _, part in pairs(stand:GetChildren()) do
if part:IsA("BasePart") and part ~= standhumRP then
local goal4 = {}
goal4.Transparency = 1
local info = TweenInfo.new(.3)
local tween4 = TweenService:Create(part,info,goal4)
tween4:Play()
tween4:Destroy()
tween4.Completed:Connect(function()
stand:Destroy()
end)
end
end
end
end
end
end)