This is a vault script for my parkour game bt its making some kind of memory leak wich is lagging my game. Please help
--Vault System
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local HRP = char:WaitForChild("HumanoidRootPart")
local Hum = char:WaitForChild("Humanoid")
local CA = Hum:LoadAnimation(script:WaitForChild("ClimbAnim"))
local ledgeavail = true
topspeed = 20
char.Humanoid.Running:Connect(function(speed)
if speed > topspeed then
ledgeavail = true
elseif speed < topspeed then
ledgeavail = false
end
while game:GetService("RunService").RenderStepped:Wait() do
r = Ray.new(HRP.Position, HRP.CFrame.LookVector * 6.5 + HRP.CFrame.UpVector * -5)
local part = workspace:FindPartOnRay(r,char)
if part and ledgeavail then
if part.Name == "Vault" then
if Hum.FloorMaterial ~= Enum.Material.Air then
if speed < topspeed then
ledgeavail = false
local Vel = Instance.new("BodyVelocity")
Vel.Parent = HRP
Vel.Velocity = Vector3.new(0,0,0)
Vel.MaxForce = Vector3.new(1,1,1) * math.huge
Vel.Velocity = HRP.CFrame.LookVector * 60 + Vector3.new(0,28,0)
CA:Play()
game.Debris:AddItem(Vel, .10)
wait(0.75)
ledgeavail = true
game.Debris:Destroy(Vel)
end
end
end
end
end
end)

3 comments
get rid of the loop from the event
game:GetService("RunService").RenderStepped:Connect()?
could you post an answer please? imnew to this