What do you want to achieve?
I want script, that i found in open source form and tried fixing it, to work like that:
when you come close to a wall (1.5 stud maximum between center of head and wall raycast), player’s head must be near ledge, minimum, is when head 1.5 stud lower than top of wall which player faces, while maximum is head higher than top of wall by 0.75 stud. Player must be facing wall and press C to hang on wall and then press space whenever player wants to climb up, but previous conditions of distance and height must be followed to hang on wall, otherwise player will just fall down.
-
What is the issue? Include screenshots / videos if possible!
I got issue with detecting and firing hang script, without following conditions. It appears after correct work with first try of hanging on wall successfully, after u climbed wall after hanging on it for first time in testing session, script then refuses to depend on conditions of height and does let you hang on wall, no matter how high the part is.
Also i cannot set the distance between wall and player needed to start hanging on wall, and instead it just works when player goes so close to wall so theres 0.1 stud gap. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried searching many topics with similar issues, topics about ray casting and functions of it, tried many times to find way to fix it by myself but didnt really get a fix.
local Character = plr.Character or plr.CharacterAdded:Wait()
local Root = Character:WaitForChild("HumanoidRootPart")
local Head = Character:WaitForChild("Head")
local Torso = Character:WaitForChild("Torso")
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
local canVault = false
while game:GetService("RunService").Heartbeat:Wait() do
local r = Ray.new(Head.CFrame.p, Head.CFrame.LookVector)
local part,position = workspace:FindPartOnRay(r,Character)
local raycastResult = workspace:Raycast(Head.CFrame.p, Head.CFrame.LookVector)
if ledgeavailable == true then
print("can grab")
else
print("cannot grab")
end
if part and ledgeavailable and not holding then
if part.Size.Y >= 7 then
if raycastResult.Distance <= 2 then
canVault = true
end
if Head.Position.Y >= part.Position.Y + ((part.Size.Y / 2) - 1) and Head.Position.Y <= part.Position.Y + (part.Size.Y / 2) and Root.Velocity.Y <= 0 and canVault then
if raycastResult then
if raycastResult.Distance <= 1 then
local key = game:GetService("UserInputService")
key.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C and ledgeavailable and not holding and canVault then
Root.Anchored = true holding = true HA:Play() ledgeavailable = false
end
end)
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,30,0)
HA:Stop() CA:Play()
game.Debris:AddItem(Vele,.15)
holding = false
wait(.75)
ledgeavailable = true
canVault = false
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
Edit: Forgot to mention, script is placed in StarterCharacterScripts, HA and CA stand for animations placed into script.