Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i make this script not lag my game and create a memory leak?

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

0

get rid of the loop from the event

0

game:GetService("RunService").RenderStepped:Connect()?

0

could you post an answer please? imnew to this

1 answer

hey you! have you ever heard of enes? if you are in trouble, better call enes!

This discussion is preserved as it was. New answers, comments, and votes are closed.