I know it involves raycasting, but I simply do not know enough about raycasting to make something like this.
Put this in a local script in starter character scripts and make two animation instances called ClimbAnim and HoldAnim
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")
local stamina = 200
ledgeavailable = true
holding = false
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
SGUI = game:GetService("StarterGui")
SGUI:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false) --// The tools in the backpack are not deleted when you do this
for _,player in ipairs(game:GetService("Players"):GetPlayers()) do
local backpack = player:FindFirstChildOfClass("Backpack")
if backpack and player.Character then
local tool
repeat
tool = player.Character:FindFirstChildOfClass("Tool")
if tool then
tool.Parent = backpack
end
until (not tool)
end
end
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,45,0)
HA:Stop() CA:Play()
game.Debris:AddItem(Vele,.15)
SGUI:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
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()
end
end)
if TouchGui then
TouchGui:WaitForChild("TouchControlFrame"):WaitForChild("JumpButton").MouseButton1Click:Connect(function()
if not holding then return end climb()
end)
end
end
while holding == true do
stamina = stamina - 1
wait(0.2)
print(stamina)
if stamina <= 0 then
climb()
end
end
2 Likes
I would recommend using ContextActionService
, where possible to do so.
How does this work? I don’t get it that much.
Basically, when it detects a touch on a ledge while you are jumping, it will hold onto it, if you press space while holding you will jump up onto the ledge
This did not work well. For clarification, I want the player to hang on the wall when you press space.
This didn’t work because you didn’t define the key.
yeah thats why i deleted it im trying a solution now
2 Likes
Don’t copy and paste scripts (especially if they’re not relevant).
1 Like
yeah sorry, its my script but i forgot that it needed to press space before climbing