Hello so i was going through the forums trying to look for why my game could be crashing and I saw a topic of memory leaks coming up. i was wondering if code like this could be the cause of memory leaks. I vaguely know what they are, and i know that it happends when something doesn’t get GC’ed, but i dont know if this would actually be a cause of it. If it is, how can i improve my code? any help is appreciated!
Script code:
game.ReplicatedStorage.Quirks.Engine["Recipro Extend"].OnClientEvent:Connect(function(char,effects,Speed)
local rootpart = char.HumanoidRootPart
if effects == true then
if workspace:FindFirstChild(char.Name .. "'s EngineExtendCharge") then
workspace:FindFirstChild(char.Name .. "'s EngineExtendCharge"):Destroy()
end
local effectsFold = Instance.new("Folder",workspace)
effectsFold.Name = char.Name .. "'s EngineExtendEffects"
debris:AddItem(effectsFold,5)
coroutine.resume(coroutine.create(function()
if char:FindFirstChild("ReciproBurst") == nil then
for i, pipes in pairs(char:GetChildren()) do
if pipes:FindFirstChild("IsAPipe") then
local Cgoal = {}
Cgoal.Size = Vector3.new(0.579, 0.4, 1)
local Cinfo = TweenInfo.new(0.09,Enum.EasingStyle.Linear)
local Ctween = TweenService:Create(pipes,Cinfo,Cgoal)
Ctween:Play()
pipes.Color = Color3.fromRGB(75, 72, 74)
pipes.Material = Enum.Material.Glass
end
end
end
end))
------------Back large rough Shock------------------
local largerough = script.GiantRough:Clone()
largerough.Size = largerough.Size / 5
largerough.CFrame = rootpart.CFrame * CFrame.Angles(math.rad(-90),0,0)
largerough.Parent = effectsFold
coroutine.resume(coroutine.create(function()
local roughgoal = {}
roughgoal.Size = largerough.Size * 5 * Speed
local roughinfo = TweenInfo.new(0.5,Enum.EasingStyle.Linear)
local roughtween = TweenService:Create(largerough,roughinfo,roughgoal)
roughtween:Play()
wait(0.30)
local roughgoal = {}
roughgoal.Transparency = 1
local roughinfo = TweenInfo.new(0.2,Enum.EasingStyle.Linear)
local roughtween = TweenService:Create(largerough,roughinfo,roughgoal)
roughtween:Play()
end))
------------Dash Shock------------------
local DashShock = script.DashShock:Clone()
DashShock.Size = DashShock.Size / 5
DashShock.CFrame = rootpart.CFrame * CFrame.Angles(math.rad(180),math.rad(180),0)
DashShock.Parent = effectsFold
coroutine.resume(coroutine.create(function()
local DashShockgoal = {}
DashShockgoal.Size = DashShock.Size * 5 * Speed
DashShockgoal.CFrame = DashShock.CFrame * CFrame.new(0,0,-24 * Speed)
local DashShockinfo = TweenInfo.new(0.5,Enum.EasingStyle.Linear)
local DashShocktween = TweenService:Create(DashShock,DashShockinfo,DashShockgoal)
DashShocktween:Play()
wait(0.30)
local DashShockgoal = {}
DashShockgoal.Transparency = 1
local DashShockinfo = TweenInfo.new(0.2,Enum.EasingStyle.Linear)
local DashShocktween = TweenService:Create(DashShock,DashShockinfo,DashShockgoal)
DashShocktween:Play()
end))
------------First Ring------------------
local RingShock = script.RingShock:Clone()
RingShock.Size = RingShock.Size / 5
RingShock.CFrame = rootpart.CFrame * CFrame.Angles(0,math.rad(90),math.rad(-90)) * CFrame.new(0,5 * Speed,0)
RingShock.Parent = effectsFold
coroutine.resume(coroutine.create(function()
local Rgoal = {}
Rgoal.Size = RingShock.Size * 5 * Speed
local Rinfo = TweenInfo.new(0.5,Enum.EasingStyle.Linear)
local Rtween = TweenService:Create(RingShock,Rinfo,Rgoal)
Rtween:Play()
wait(0.30)
local Rgoal = {}
Rgoal.Transparency = 1
local Rinfo = TweenInfo.new(0.2,Enum.EasingStyle.Linear)
local Rtween = TweenService:Create(RingShock,Rinfo,Rgoal)
Rtween:Play()
end))
------------Second Ring------------------
local RingShock = script.RingShock:Clone()
RingShock.Size = RingShock.Size / 5
RingShock.CFrame = rootpart.CFrame * CFrame.Angles(0,math.rad(90),math.rad(-90)) * CFrame.new(0,45 * Speed,0)
RingShock.Parent = effectsFold
coroutine.resume(coroutine.create(function()
local Rgoal = {}
Rgoal.Size = RingShock.Size * 5 * Speed
local Rinfo = TweenInfo.new(0.5,Enum.EasingStyle.Linear)
local Rtween = TweenService:Create(RingShock,Rinfo,Rgoal)
Rtween:Play()
wait(0.30)
local Rgoal = {}
Rgoal.Transparency = 1
local Rinfo = TweenInfo.new(0.2,Enum.EasingStyle.Linear)
local Rtween = TweenService:Create(RingShock,Rinfo,Rgoal)
Rtween:Play()
end))
------------Thurd Ring------------------
local RingShock = script.RingShock:Clone()
RingShock.Size = RingShock.Size / 5
RingShock.CFrame = rootpart.CFrame * CFrame.Angles(0,math.rad(90),math.rad(-90)) * CFrame.new(0,75 * Speed,0)
RingShock.Parent = effectsFold
coroutine.resume(coroutine.create(function()
local Rgoal = {}
Rgoal.Size = RingShock.Size * 5 * Speed
local Rinfo = TweenInfo.new(0.5,Enum.EasingStyle.Linear)
local Rtween = TweenService:Create(RingShock,Rinfo,Rgoal)
Rtween:Play()
wait(0.30)
local Rgoal = {}
Rgoal.Transparency = 1
local Rinfo = TweenInfo.new(0.2,Enum.EasingStyle.Linear)
local Rtween = TweenService:Create(RingShock,Rinfo,Rgoal)
Rtween:Play()
end))
------------Fourth Ring------------------
local RingShock = script.RingShock:Clone()
RingShock.Size = RingShock.Size / 5
RingShock.CFrame = rootpart.CFrame * CFrame.Angles(0,math.rad(90),math.rad(-90)) * CFrame.new(0,100 * Speed,0)
RingShock.Parent = effectsFold
coroutine.resume(coroutine.create(function()
local Rgoal = {}
Rgoal.Size = RingShock.Size * 5 * Speed
local Rinfo = TweenInfo.new(0.5,Enum.EasingStyle.Linear)
local Rtween = TweenService:Create(RingShock,Rinfo,Rgoal)
Rtween:Play()
wait(0.30)
local Rgoal = {}
Rgoal.Transparency = 1
local Rinfo = TweenInfo.new(0.2,Enum.EasingStyle.Linear)
local Rtween = TweenService:Create(RingShock,Rinfo,Rgoal)
Rtween:Play()
end))
------------Fifth Ring------------------
local RingShock = script.RingShock:Clone()
RingShock.Size = RingShock.Size / 5
RingShock.CFrame = rootpart.CFrame * CFrame.Angles(0,math.rad(90),math.rad(-90)) * CFrame.new(0,125 * Speed,0)
RingShock.Parent = effectsFold
coroutine.resume(coroutine.create(function()
local Rgoal = {}
Rgoal.Size = RingShock.Size * 5 * Speed
local Rinfo = TweenInfo.new(0.5,Enum.EasingStyle.Linear)
local Rtween = TweenService:Create(RingShock,Rinfo,Rgoal)
Rtween:Play()
wait(0.30)
local Rgoal = {}
Rgoal.Transparency = 1
local Rinfo = TweenInfo.new(0.2,Enum.EasingStyle.Linear)
local Rtween = TweenService:Create(RingShock,Rinfo,Rgoal)
Rtween:Play()
end))
------------Wind Shock------------------
local Wind = script.Wind:Clone()
Wind.Size = Wind.Size / 5
Wind.CFrame = rootpart.CFrame * CFrame.Angles(math.rad(90),math.rad(180),0)
Wind.Parent = effectsFold
coroutine.resume(coroutine.create(function()
local Rgoal = {}
Rgoal.Size = Wind.Size * 5 * Speed
Rgoal.CFrame = Wind.CFrame * CFrame.new(0,-30 * Speed,0)
local Rinfo = TweenInfo.new(0.5,Enum.EasingStyle.Linear)
local Rtween = TweenService:Create(Wind,Rinfo,Rgoal)
Rtween:Play()
wait(0.30)
local Rgoal = {}
Rgoal.Transparency = 1
local Rinfo = TweenInfo.new(0.2,Enum.EasingStyle.Linear)
local Rtween = TweenService:Create(Wind,Rinfo,Rgoal)
Rtween:Play()
end))
------------Deep Shock------------------
local Deep = script.Deep:Clone()
Deep.Size = Deep.Size / 5
Deep.CFrame = rootpart.CFrame * CFrame.Angles(0,math.rad(90),math.rad(90))
Deep.Parent = effectsFold
coroutine.resume(coroutine.create(function()
local Rgoal = {}
Rgoal.Size = Deep.Size * 5 * Speed
Rgoal.CFrame = Deep.CFrame * CFrame.new(0,-30 * Speed,0)
local Rinfo = TweenInfo.new(0.5,Enum.EasingStyle.Linear)
local Rtween = TweenService:Create(Deep,Rinfo,Rgoal)
Rtween:Play()
wait(0.30)
local Rgoal = {}
Rgoal.Transparency = 1
local Rinfo = TweenInfo.new(0.2,Enum.EasingStyle.Linear)
local Rtween = TweenService:Create(Deep,Rinfo,Rgoal)
Rtween:Play()
end))
------------HugeRough Shock------------------
local Rough = script.HugeRough:Clone()
Rough.Size = Rough.Size / 5
Rough.CFrame = rootpart.CFrame * CFrame.Angles(math.rad(-90),0,0) * CFrame.new(0,60*Speed,0)
Rough.Parent = effectsFold
coroutine.resume(coroutine.create(function()
local Rgoal = {}
Rgoal.Size = Rough.Size * 5 * Speed
Rgoal.CFrame = Rough.CFrame
local Rinfo = TweenInfo.new(0.5,Enum.EasingStyle.Linear)
local Rtween = TweenService:Create(Rough,Rinfo,Rgoal)
Rtween:Play()
wait(0.30)
local Rgoal = {}
Rgoal.Transparency = 1
local Rinfo = TweenInfo.new(0.2,Enum.EasingStyle.Linear)
local Rtween = TweenService:Create(Rough,Rinfo,Rgoal)
Rtween:Play()
end))
------------LargeRough Shock------------------
local Rough = script.LargeRough:Clone()
Rough.Size = Rough.Size / 5
Rough.CFrame = rootpart.CFrame * CFrame.Angles(math.rad(-90),0,0) * CFrame.new(0,75*Speed,0)
Rough.Parent = effectsFold
coroutine.resume(coroutine.create(function()
local Rgoal = {}
Rgoal.Size = Rough.Size * 5 * Speed
Rgoal.CFrame = Rough.CFrame
local Rinfo = TweenInfo.new(0.5,Enum.EasingStyle.Linear)
local Rtween = TweenService:Create(Rough,Rinfo,Rgoal)
Rtween:Play()
wait(0.30)
local Rgoal = {}
Rgoal.Transparency = 1
local Rinfo = TweenInfo.new(0.2,Enum.EasingStyle.Linear)
local Rtween = TweenService:Create(Rough,Rinfo,Rgoal)
Rtween:Play()
end))
------------MediumRough Shock------------------
local Rough = script.MediumRough:Clone()
Rough.Size = Rough.Size / 5
Rough.CFrame = rootpart.CFrame * CFrame.Angles(math.rad(-90),0,0) * CFrame.new(0,90*Speed,0)
Rough.Parent = effectsFold
coroutine.resume(coroutine.create(function()
local Rgoal = {}
Rgoal.Size = Rough.Size * 5 * Speed
Rgoal.CFrame = Rough.CFrame
local Rinfo = TweenInfo.new(0.5,Enum.EasingStyle.Linear)
local Rtween = TweenService:Create(Rough,Rinfo,Rgoal)
Rtween:Play()
wait(0.30)
local Rgoal = {}
Rgoal.Transparency = 1
local Rinfo = TweenInfo.new(0.2,Enum.EasingStyle.Linear)
local Rtween = TweenService:Create(Rough,Rinfo,Rgoal)
Rtween:Play()
end))
------------SmallRough Shock------------------
local Rough = script.SmallRough:Clone()
Rough.Size = Rough.Size / 5
Rough.CFrame = rootpart.CFrame * CFrame.Angles(math.rad(-90),0,0) * CFrame.new(0,102*Speed,0)
Rough.Parent = effectsFold
coroutine.resume(coroutine.create(function()
local Rgoal = {}
Rgoal.Size = Rough.Size * 5 * Speed
Rgoal.CFrame = Rough.CFrame
local Rinfo = TweenInfo.new(0.5,Enum.EasingStyle.Linear)
local Rtween = TweenService:Create(Rough,Rinfo,Rgoal)
Rtween:Play()
wait(0.30)
local Rgoal = {}
Rgoal.Transparency = 1
local Rinfo = TweenInfo.new(0.2,Enum.EasingStyle.Linear)
local Rtween = TweenService:Create(Rough,Rinfo,Rgoal)
Rtween:Play()
end))
elseif effects == "Charging" then
local charingfolder = Instance.new("Folder",workspace)
charingfolder.Name = char.Name .. "'s EngineExtendCharge"
debris:AddItem(charingfolder,1)
local ball = script:WaitForChild("Ball"):Clone()
ball.Parent = charingfolder
ball.CFrame = char.RightUpperLeg.CFrame
ball.Name = "ExploGrenChargeBall"
local ball2 = script:WaitForChild("Ball"):Clone()
ball2.Parent = charingfolder
ball2.CFrame = char.LeftUpperLeg.CFrame
ball2.Name = "ExploGrenChargeBall2"
local weld = Instance.new("WeldConstraint")
weld.Part0 = char.RightLowerLeg
weld.Part1 = ball
weld.Parent = char.RightLowerLeg
local weld = Instance.new("WeldConstraint")
weld.Part0 = char.RightUpperLeg
weld.Part1 = ball2
weld.Parent = char.RightUpperLeg
coroutine.resume(coroutine.create(function()
if char:FindFirstChild("ReciproBurst") == nil then
for i, pipes in pairs(char:GetChildren()) do
if pipes:FindFirstChild("IsAPipe") then
local Cgoal = {}
Cgoal.Size = Vector3.new(1.5, 1.5, 1.5)
local Cinfo = TweenInfo.new(1,Enum.EasingStyle.Linear)
local Ctween = TweenService:Create(pipes,Cinfo,Cgoal)
Ctween:Play()
pipes.Color = Color3.fromRGB(2, 225, 210)
pipes.Material = Enum.Material.Neon
end
end
end
end))
coroutine.resume(coroutine.create(function()
while workspace:FindFirstChild(char.Name .. "'s EngineExtendCharge") do
local randomvar = math.random(-360,360)
ball.Orientation = ball.Orientation + Vector3.new(randomvar,randomvar,randomvar)
local charge = script:WaitForChild("ChargeFXO"):Clone()
charge.CFrame = ball.CFrame * CFrame.new(0,-3,0)
charge.Orientation = Vector3.new(ball.Orientation.X,ball.Orientation.Y,ball.Orientation.Z)
charge.Parent = charingfolder
local posgoal = {}
posgoal.CFrame = ball.CFrame
posgoal.Size = charge.Size / 5
posgoal.Transparency = 1
local posinfo = TweenInfo.new(0.2,Enum.EasingStyle.Linear)
local postween = TweenService:Create(charge,posinfo,posgoal)
postween:Play()
task.wait(1/60)
end
end))
coroutine.resume(coroutine.create(function()
while workspace:FindFirstChild(char.Name .. "'s EngineExtendCharge") do
local randomvar = math.random(-360,360)
ball2.Orientation = ball2.Orientation + Vector3.new(randomvar,randomvar,randomvar)
local charge = script:WaitForChild("ChargeFXY"):Clone()
charge.CFrame = ball2.CFrame * CFrame.new(0,-3,0)
charge.Orientation = Vector3.new(ball2.Orientation.X,ball2.Orientation.Y,ball2.Orientation.Z)
charge.Parent = charingfolder
local posgoal = {}
posgoal.CFrame = ball2.CFrame
posgoal.Size = charge.Size / 5
posgoal.Transparency = 1
local posinfo = TweenInfo.new(0.2,Enum.EasingStyle.Linear)
local postween = TweenService:Create(charge,posinfo,posgoal)
postween:Play()
task.wait(1/60)
end
end))
end
end)