Hey there! I’m making a script where you can grab onto a ledge, but the problem is, is that it doesn’t connect to the ledge correctly:
Any ways to fix this?
Important parts of the code:
local headTopRay = workspace:Raycast(humanoid.RootPart.Position+Vector3.new(0,2.5,0), humanoid.RootPart.CFrame.LookVector*2, rayParams)
local headMidRay = workspace:Blockcast(humanoid.RootPart.CFrame*CFrame.new(0,-.5,0), Vector3.new(.1,5,.1), humanoid.RootPart.CFrame.LookVector*1.5, rayParams)
if not headTopRay and headMidRay then
local direction = headMidRay.Normal:Cross(Vector3.new(0, 1, 0))
local rotation = CFrame.lookAt(Vector3.new(0,0,0), direction * Vector3.new(1, 0, 1))
humanoid.RootPart.CFrame = CFrame.new(humanoid.RootPart.Position) * rotation
-- ^ Rotates the player to make sure it's adjacent to the wall
humanoid.RootPart.Anchored = true
delay(0, function()
while grabbing do
humanoid.AutoRotate = false
local direction = -headMidRay.Normal
local rotation = CFrame.lookAt(Vector3.new(0,0,0), direction * Vector3.new(1, 0, 1))
humanoid.RootPart.CFrame = CFrame.new(humanoid.RootPart.Position) * rotation
runService.RenderStepped:Wait()
end
end)
-- Rest of the code
end
Any help is appreciated!