I again need help with my ledge climbing script

Hello! it is me about 5-7 hours later asking for help here, again!
I feel pretty guilty for relying on the developer’s forum so much but I just can’t seem to add a system that makes the player falls down after holding on to the ledge for a while
here is the code if you’re looking for it :

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 HSA = Hum:LoadAnimation(script:WaitForChild("HoldSAnim"))
local TouchGui = plr:WaitForChild("PlayerGui"):FindFirstChild("TouchGui")
local UIS = game:GetService("UserInputService")

ledgeavailable = true
holding = false

while game:GetService("RunService").Heartbeat:Wait() do
	local r = Ray.new(Head.CFrame.p, Head.CFrame.LookVector * 3)
	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
				wait()
				Root.Anchored = true 
				holding = true 
				ledgeavailable = false
				HA:Play()
				wait(0.005)
				HSA:Play(0.25)
			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 * 20 + Vector3.new(0,30,0)
		HA:Stop() CA:Play(0.1)
		game.Debris:AddItem(Vele,.15)
		holding = false
		Hum.WalkSpeed = 23
		wait(.75)
		ledgeavailable = true
		Hum.WalkSpeed = 30
	end
	
	UIS.InputBegan:Connect(function(Key,Chat)
		if not holding then return end 
		if Key.KeyCode == Enum.KeyCode.Space and not Chat then
			climb()
		end
	end)
	
	if TouchGui then
		TouchGui:WaitForChild("TouchControlFrame"):WaitForChild("JumpButton").MouseButton1Click:Connect(function()
			if not holding then return end climb()
		end)
	end
end

and yes I have been trying for the past hour either simply adding a single line of wait() and then making them fall down but it will still make them fall down even after I have climbed the ledge later. another solution I tried is to put in if holding and not ledgeavailable then but that seems to uh quite make the code backfire and doesn’t work anymore
if anyone got a solution to this please tell me

Two months late I know, but you can add a “while not ledgeavailable do” argument.
Take this for example:

	function loose()
		Root.Anchored = false
		if Root:FindFirstChildOfClass("BodyVelocity") then
			Root.BodyVelocity:Destroy()
		end
		HA:Stop() CA:Stop()
		holding = false
		Hum.AutoRotate = true
		wait(1)
		ledgeavailable = true
	end
	
	while not ledgeavailable do
		wait(0.3)
		if holding then
			loose()
		end
	end
1 Like

You should probably place them after the climb() function

1 Like