Recently learned about memory leaks and i’ve been remaking my combat system. Would this cause memory leak?
local Fist = {}
local CanAttack = require(game.ServerStorage.Modules.Functions.CanAttack)
local Hitbox = require(script.Hitbox)
local Debris = game:GetService("Debris")
Fist.Light = function(player)
local char
if player:IsA("Player") then
char = player.Character
else
char = player
end
local hum = char.Humanoid
local Root = char.HumanoidRootPart
local Effects = char.Effects
local combo = Effects.Combo
if CanAttack(char) == false then
return
end
local Last = false
combo.Value += 1
if combo.Value == 4 then
Last = true
task.delay(.5,function()
combo.Value = 0
end)
end
local lastHit = combo.Value
task.delay(1,function()
if combo.Value == lastHit then
combo.Value = 0
end
end)
local attacking = Instance.new("BoolValue")
attacking.Name = "Attacking"
attacking.Parent = Effects
local s = game.ServerScriptService.Services.DamageService.Swing:Clone()
s.Parent = char.Head
s.Playing = true
Debris:AddItem(s,1)
if not Last then
Debris:AddItem(attacking,.55)
else
local Bvel = Instance.new("BodyVelocity")
Bvel.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
Bvel.Velocity = Root.CFrame.LookVector*25
Bvel.Parent = Root
Debris:AddItem(Bvel,.1)
task.delay(.45,function()
local Speed = Instance.new("IntValue")
Speed.Name = "SpeedSet"
Speed.Value = 0
Speed.Parent = Effects
Debris:AddItem(Speed,0.6)
end)
Debris:AddItem(attacking,1.15)
end
hum.Animator:LoadAnimation(char.Anims.Normal["Light"..combo.Value]):Play()
game.ReplicatedStorage.Events.TweenCam:FireClient(player,"M1")
Hitbox.Hitbox(player,4,1,"Light")
end
Fist.Heavy = function(player)
local char
if player:IsA("Player") then
char = player.Character
else
char = player
end
local hum = char.Humanoid
local Root = char.HumanoidRootPart
local Effects = char.Effects
local combo = Effects.Combo
if CanAttack(char) == false then
return
end
local attacking = Instance.new("BoolValue")
attacking.Name = "Attacking"
attacking.Parent = Effects
Debris:AddItem(attacking,1.3)
local Speed = Instance.new("IntValue")
Speed.Name = "SpeedSet"
Speed.Value = 6
Speed.Parent = Effects
Debris:AddItem(Speed,0.6)
local anim = hum:LoadAnimation(char.Anims.Normal.Light4)
game.ReplicatedStorage.Events.TweenCam:FireClient(player,"M2")
anim:Play()
task.delay(.2,function()
anim:AdjustSpeed(.1)
end)
task.wait(.5)
anim:AdjustSpeed(1)
local Bvel = Instance.new("BodyVelocity")
Bvel.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
Bvel.Velocity = Root.CFrame.LookVector*25
Bvel.Parent = Root
Debris:AddItem(Bvel,.1)
local Speed = Instance.new("IntValue")
Speed.Name = "SpeedSet"
Speed.Value = 0
Speed.Parent = Effects
Debris:AddItem(Speed,0.6)
Hitbox.Hitbox(player,6,1,"Heavy")
end
Fist.Block = function(player,State)
local char
if player:IsA("Player") then
char = player.Character
else
char = player
end
local hum = char.Humanoid
local Effects = char.Effects
if CanAttack(char) == false then
return
end
local anim = hum.Animator:LoadAnimation(char.Anims.Normal.Block)
anim:Play()
game.ReplicatedStorage.Events.TweenCam:FireClient(player,"M1")
local Blocking = Instance.new("BoolValue")
Blocking.Name = "Block"
Blocking.Parent = Effects
Debris:AddItem(Blocking,.5)
local Attacking = Instance.new("BoolValue")
Attacking.Name = "Attacking"
Attacking.Parent = Effects
Debris:AddItem(Attacking,.8)
local Speed = Instance.new("IntValue")
Speed.Name = "SpeedSet"
Speed.Value = 5
Speed:SetAttribute("State","Block")
Speed.Parent = Effects
Debris:AddItem(Speed,.5)
task.delay(.5,function()
anim:Stop()
end)
end
return Fist