I have this script here in 'StarterPlayerScripts" that allows the player to climb any wall with a slope higher than 89. I’ve been debugging and found out it doesn’t detect the collided part as a BasePart(line 3). I’ve also tried replacing line 3 with "IsA(“Part)” and it still doesn’t detect. Any ideas?
local minSlopeAngle = 89
local function onCollision(hit)
if hit and hit:IsA("BasePart") and hit.CanCollide then
local surfaceNormal = hit.CFrame:VectorToWorldSpace(Vector3.new(0, 1, 0))
if surfaceNormal.Magnitude > 0.01 then -- make sure the normal is normalized
local slopeAngle = math.deg(math.acos(surfaceNormal:Dot(Vector3.new(0, 1, 0))))
if slopeAngle >= minSlopeAngle then
local humanoid = game.Players.LocalPlayer.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
humanoid.AutoRotate = false
humanoid.AutoRotateSpeed = 0
local startTime = tick()
while tick() - startTime < 1 do
local climbDirection = Vector3.new(0, 1, 0)
humanoid:MoveTo(humanoid.RootPart.Position + climbDirection)
wait()
end
end
end
end
end
end
game.Players.LocalPlayer.Character.HumanoidRootPart.Touched:Connect(onCollision)