I want my ledge climbing script to work on all sides like in this.
but when I try to climb the same ledges but on a different side, the character goes inside the ledge and is unable to move
but when it does work on a different side the player cant even go up.
this is the line of code that activates the ledge climbing
for i,v in pairs(Char:GetChildren()) do
if v:IsA("Part") then
v.Touched:Connect(function(touch)
if touch.Name == "Ledge" then
if CanClimbLedge == true then
HRP.Anchored = true
Hum.AutoRotate = false
onLedge = true
CanClimbLedge = false
CurrentLedge = touch
RotatePlayerEvent:FireServer(touch,HRP,Char,CurrentLedge)
HRP.CFrame = CFrame.new(HRP.CFrame.X,CurrentLedge.CFrame.Y,CurrentLedge.CFrame.Z) * CFrame.new(0,-2,1)
Char:PivotTo(Char:GetPivot() * CFrame.Angles(0,math.rad(-CurrentLedge.Rotation.Y),0))
IdleClimbAnimation:Play()
end
end
end)
end
end
and this is the Raycasting to check if the player can go up
RunService.RenderStepped:Connect(function()
local Head = Char:WaitForChild("Head")
local rayParams = RaycastParams.new()
rayParams.IgnoreWater = true
rayParams.FilterType = Enum.RaycastFilterType.Blacklist
rayParams.FilterDescendantsInstances = {script.Parent}
local ClimbUpRayOrigin = Head.CFrame.UpVector * 3 + Head.Position
local ClimbUpRayDirection = Head.CFrame.LookVector * 15
local ClimbUpRayResults = workspace:Raycast(ClimbUpRayOrigin,ClimbUpRayDirection,rayParams)
if ClimbUpRayResults then
if ClimbUpRayResults.Instance.Name == "Ledge" then
CanClimbUp = true
end
if ClimbUpRayResults.Instance.Name ~= "Ledge" then
CanClimbUp = false
end
end
if CanClimbUp == true and onLedge == true and IsLeaping == false and IsPressingWInput == true then
if ClimbUpRayResults.Instance:GetAttribute("Vertical") then
local goal = {
CFrame = CFrame.new(ClimbUpRayResults.Instance.Position.X,ClimbUpRayResults.Instance.Position.Y,HRP.CFrame.Z) * CFrame.new(0,-3,0)
}
local ti = TweenInfo.new(0.2,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0,false,0)
local Tween = tweenservice:Create(HRP,ti,goal)
Tween:Play()
end
end
end)
what is wrong?