I previously made a post asking why my game was getting insanely laggy. I found out that it was a memory leak and I spent half an hour locating it. The problem? I can’t figure out how to patch it, and have spent around an hour researching and looking through this code trying to find what isn’t being collected.
events.Remote.Run.OnServerEvent:Connect(function(plr, held)
local char:Model = plr.Character
local anims = char:FindFirstChild("Anims")
--print(char:GetAttribute("Stamina"))
if plr.InRound.Value ~= true then
return
end
if held == true and char:GetAttribute("Stamina") > 0 and plr.Character.HumanoidRootPart.AssemblyLinearVelocity.Magnitude > 0 and plr.InRound.Value == true then
--char:SetAttribute("Speed", char:GetAttribute("RunSpeed") * char.SpeedMultiplier.Value)
if char:GetAttribute("Stamina") >= 10 then
char:SetAttribute("Stamina", char:GetAttribute("Stamina") - 0.3)
plr.PlayerGui.GameGui.Stats.StaminaBar.Bar.BackgroundColor3 = Color3.new(1, 1, 1)
if char:GetAttribute("Running") == false then
char:SetAttribute("Running", true)
--char:SetAttribute("Speed", char:GetAttribute("RunSpeed") * char.SpeedMultiplier.Value)
char.Humanoid:LoadAnimation(char.Anims.Run):Play(0.2, 1, char.SpeedMultiplier.Value)
end
char:SetAttribute("Speed", char:GetAttribute("RunSpeed") * char.SpeedMultiplier.Value)
for i, track:AnimationTrack in char.Humanoid:GetPlayingAnimationTracks() do
if track.Name == "Run" then
track:AdjustSpeed(char.SpeedMultiplier.Value)
end
end
--task.wait(0.01)
repeat task.wait() until not held
else
char:SetAttribute("Stamina", char:GetAttribute("Stamina") - 0.3)
plr.PlayerGui.GameGui.Stats.StaminaBar.Bar.BackgroundColor3 = Color3.new(1, 0, 0)
end
--[[char:SetAttribute("Stamina", char:GetAttribute("Stamina") - 0.3)
if char:GetAttribute("Running") == false then
char:SetAttribute("Running", true)
--char:SetAttribute("Speed", char:GetAttribute("RunSpeed") * char.SpeedMultiplier.Value)
char.Humanoid:LoadAnimation(char.Anims.Run):Play(0.2, 1, char.SpeedMultiplier.Value)
end
char:SetAttribute("Speed", char:GetAttribute("RunSpeed") * char.SpeedMultiplier.Value)
for i, track:AnimationTrack in char.Humanoid:GetPlayingAnimationTracks() do
if track.Name == "Run" then
track:AdjustSpeed(char.SpeedMultiplier.Value)
end
end
--task.wait(0.01)
repeat task.wait() until not held]]
end
if held == false or char:GetAttribute("Stamina") <= 0 or plr.Character.HumanoidRootPart.AssemblyLinearVelocity.Magnitude == 0 and state == "Round" and plr.InRound.Value == true then
plr.PlayerGui.GameGui.Stats.StaminaBar.Bar.BackgroundColor3 = Color3.new(1, 1, 1)
char:SetAttribute("Speed", char:GetAttribute("WalkSpeed") * char.SpeedMultiplier.Value)
char:SetAttribute("Running", false)
if char:GetAttribute("Stamina") <= char:GetAttribute("MaxStamina") and held == false then
char:SetAttribute("Stamina", char:GetAttribute("Stamina") + 0.35)
if char:GetAttribute("Stamina") > char:GetAttribute("MaxStamina") then
char:SetAttribute("Stamina", char:GetAttribute("MaxStamina"))
end
--task.wait(0.01)
end
--[[for i, track:AnimationTrack in char.Humanoid:GetPlayingAnimationTracks() do
if track.Name == "Run" then
track:Stop(0.4)
end
end]]
end
held = nil
char = nil
anims = nil
end)
Keep in mind that I am VERY new to memory leaks and how to spot them. I just need help finding out where it is, I can’t find it no matter how much I research or read through the code.