Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

:Clone() causes massive fps drop?? [SOLVED]

Asked by 3 years ago
Edited 3 years ago

Uh so yeah, look at this. As you can see I get a huge fps drop after the fireball exploded, how and why does that happen?

local Tweenservice = game:GetService("TweenService")
local explosioninfo = TweenInfo.new(2.5,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,0,false,0)
local newblast = script.Parent
local assets = game.ReplicatedStorage.FireAssets
local db = false

local damagebonus = script.Parent.damagebonus.Value

newblast.Touched:Connect(function(hit)
    if hit ~= nil then
        if hit.CanCollide == true then
            if not db then
                db = true
                print(hit.Name)
                newblast.Anchored = true
                newblast.ba.Enabled = false
                newblast.w.Enabled = false

                local angularCFrame = CFrame.Angles(math.rad(math.random(-180, 180)), math.rad(math.random(-180, 180)), math.rad(math.random(-180, 180)))

                local a = assets.QMove.ontouch.a:Clone()
                a.Parent = workspace
                a.CFrame = newblast.CFrame * angularCFrame

                local b = assets.QMove.ontouch.a:Clone()
                b.Parent = workspace
                b.Name = "b1"
                b.CFrame = newblast.CFrame * CFrame.Angles(math.rad(math.random(-150, 150)), math.rad(math.random(-150, 150)), math.rad(math.random(-150, 150)))

                local c = assets.QMove.ontouch.a:Clone()
                c.Parent = workspace
                c.Name = "c1"
                c.CFrame = newblast.CFrame * CFrame.Angles(math.rad(math.random(-120, 120)), math.rad(math.random(-120, 120)), math.rad(math.random(-120, 120)))

                local d = assets.QMove.ontouch.a:Clone()
                d.Parent = workspace
                d.Name = "d1"
                d.CFrame = newblast.CFrame * CFrame.Angles(math.rad(math.random(-90,90)), math.rad(math.random(-90, 90)), math.rad(math.random(-90, 90)))

                local e = assets.QMove.ontouch.a:Clone()
                e.Parent = workspace
                e.Name = "e1"
                e.CFrame = newblast.CFrame * CFrame.Angles(math.rad(math.random(-60, 60)), math.rad(math.random(-60, 60)), math.rad(math.random(-60, 60)))

                local f = assets.QMove.ontouch.a:Clone()
                f.Parent = workspace
                f.Name = "f1"
                f.CFrame = newblast.CFrame * CFrame.Angles(math.rad(math.random(-30, 30)), math.rad(math.random(-30, 30)), math.rad(math.random(-30,30)))

                local tween = Tweenservice:Create(a,explosioninfo,{Size = Vector3.new(44.36, 1.768, 42.97)})
                tween:Play()
                Tweenservice:Create(b,explosioninfo,{Size = Vector3.new(64.301, 1.768, 68.047)}):Play()
                Tweenservice:Create(c,explosioninfo,{Size = Vector3.new(64.301, 1.768, 68.047)}):Play()
                Tweenservice:Create(d,explosioninfo,{Size = Vector3.new(64.301, 1.768, 68.047)}):Play()
                Tweenservice:Create(e,explosioninfo,{Size = Vector3.new(64.301, 1.768, 68.047)}):Play()
                Tweenservice:Create(f,explosioninfo,{Size = Vector3.new(64.301, 1.768, 68.047)}):Play()
                wait(0.1)

                local transparencytween = Tweenservice:Create(a,explosioninfo,{Transparency = 1})
                transparencytween:Play()
                Tweenservice:Create(b,TweenInfo.new(3,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{Transparency = 1}):Play()
                Tweenservice:Create(c,TweenInfo.new(3,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{Transparency = 1}):Play()
                Tweenservice:Create(d,TweenInfo.new(3,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{Transparency = 1}):Play()
                Tweenservice:Create(e,TweenInfo.new(3,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{Transparency = 1}):Play()
                Tweenservice:Create(f,TweenInfo.new(3,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{Transparency = 1}):Play()

                local explosionsound = script.Parent.Sounds.hit
                explosionsound:Play()

                a.Attachment.explode1.Enabled = true
                a.Attachment.explode2.Enabled = true
                a.Attachment.explode3.Enabled = true
                a.Attachment.explode4.Enabled = true
                wait(0.2)

                a.Attachment.explode1.Enabled = false
                a.Attachment.explode2.Enabled = false
                a.Attachment.explode3.Enabled = false
                a.Attachment.explode4.Enabled = false

                for i, v in pairs(workspace:GetChildren()) do
                    if v ~= workspace:FindFirstChild(newblast:FindFirstChild("Owner").Value) then
                        if v:FindFirstChild("HumanoidRootPart") and v:FindFirstChildOfClass("Humanoid") then
                            local hum = v:FindFirstChildOfClass("Humanoid")
                            local humrp = v:FindFirstChild("HumanoidRootPart")
                            if hum.Health > 0 then
                                if (newblast.Position - humrp.Position).magnitude < 13.5 then
                                    hum:TakeDamage(1000 + damagebonus)
                                    damagebonus = 0
                                end
                            end
                        end
                    end
                end

                transparencytween.Completed:Wait()
                a:Destroy()
                b:Destroy()
                c:Destroy()
                d:Destroy()
                e:Destroy()
                f:Destroy()
                newblast:Destroy()
                wait(.5)
                db = false
            end
        end
    end
end)

1 answer

Log in to vote
1
Answered by 3 years ago

Oh right , fixed it by myself. I change those effects parent from workspace to player character.

0
Make sure to mark "SOLVED" in the title! speedyfox66 237 — 3y
0
Oh yeah , forgot bout that Salvin_Gaming 10 — 3y
Ad

Answer this question