Ledge Climb Script, Anchored?

Hello, I’ve been trying to make a ledge climb system, where you can move around in the ledge,by pressing a, or d, but whenever i try, my humanoid root parts gets frozen, can someone explain to me what i’m doing wrong?

local plr = game.Players.LocalPlayer
local Character = plr.Character or plr.CharacterAdded:Wait()
local Root = Character:WaitForChild("HumanoidRootPart")
local Head = Character:WaitForChild("Head")
local Hum = Character:WaitForChild("Humanoid")
local CA = Hum:LoadAnimation(script:WaitForChild("ClimbAnim"))
local HA = Hum:LoadAnimation(script:WaitForChild("HoldAnim"))
local TouchGui = plr:WaitForChild("PlayerGui"):FindFirstChild("TouchGui")
local UIS = game:GetService("UserInputService")

ledgeavailable = true
holding = false

function sideclimb(code)
	local bodyVeloSideClimb = Root:FindFirstChild("bodyVeloSideClimb")
	Root.Anchored = false
	if code == "A" then
		bodyVeloSideClimb.Velocity = Root.CFrame.RightVector * -1
	elseif code == "D" then
		bodyVeloSideClimb.Velocity = Root.CFrame.RightVector
	end
end

function endsideclimb(code)
	Root.Anchored = true
	local bodyVeloSideClimb = Root:FindFirstChild("bodyVeloSideClimb")
	bodyVeloSideClimb.Velocity = Vector3.new(0,0,0)
end

while game:GetService("RunService").Heartbeat:Wait() do
	local r = Ray.new(Head.CFrame.p, Head.CFrame.LookVector * 5)
	local part,position = workspace:FindPartOnRay(r,Character)
	
	if part and ledgeavailable and not holding then
		if part.Size.Y >= 7 then
			if Head.Position.Y >= (part.Position.Y + (part.Size.Y / 2)) - 1 and Head.Position.Y <= part.Position.Y + (part.Size.Y / 2) and Hum.FloorMaterial == Enum.Material.Air and Root.Velocity.Y <= 0 then
				Root.Anchored = true
				holding = true HA:Play() ledgeavailable = false
			end
		end
	end
	
	function climb()
		local Vele = Instance.new("BodyVelocity",Root)
		Root.Anchored = false
		Vele.MaxForce = Vector3.new(1,1,1) * math.huge
		Vele.Velocity = Root.CFrame.LookVector * 10 + Vector3.new(0,30,0)
		HA:Stop() CA:Play()
		game.Debris:AddItem(Vele,.15)
		holding = false
		wait(.75)
		ledgeavailable = true
	end
	
	UIS.InputBegan:Connect(function(Key,Chat)
		if not holding then
			return 
		end 
		if Key.KeyCode == Enum.KeyCode.Space and not Chat then
			climb()
		elseif Key.KeyCode == Enum.KeyCode.A and not Chat then
			sideclimb("A")
		elseif Key.KeyCode == Enum.KeyCode.D and not Chat then
			sideclimb("D")
		end
	end)
	
	UIS.InputEnded:Connect(function(Key, Chat)
		if not holding then
			return 
		end 
		if Key.KeyCode == Enum.KeyCode.A and not Chat then
			endsideclimb()
		elseif Key.KeyCode == Enum.KeyCode.D and not Chat then
			endsideclimb()
		end
	end)
	
	if TouchGui then
		TouchGui:WaitForChild("TouchControlFrame"):WaitForChild("JumpButton").MouseButton1Click:Connect(function()
			if not holding then	return	end	climb()
		end)
	end
end
1 Like

You have Anchored the Rig , Body Movers doesn’t work on Anchored parts

is there any changes in the scripts you can recommend?

oh and,

please read the code before replying, i already unanchored before the velocity

Sorry didn’t see that .Before helping you with fixing this bug I would ask you to stop redefining the events in the while loop , this could create a large amount connection which would stack up in memory and cause memory leak. It would be also good if you did :

local function Hello()

end

Instead of

function Hello()

end

You should always use local variables.

Now for your issue , try manually checking whether a body velocity exists and check its velocity. If don’t you see movement try manipulating its properties.

1 Like