So I have this script and its supposed to rotate my player according to the slope and it does that but the problem is that when im not on a slope or something it weird rotates my character
connection = game:GetService("RunService").Heartbeat:Connect(function()
local r = Ray.new(root.Position, Vector3.new(0,-(humanoid.HipHeight + 4),0))
local hit,pos,normal = workspace:FindPartOnRayWithIgnoreList(r,{character})
local vector = (root.CFrame - root.CFrame.p):VectorToObjectSpace(normal)
if vector.z > 0 then
root.RootJoint.C0 = CFrame.new(0,vector.z * 1.25,0,-1,0,0,0,0,1,0,1,0) * CFrame.Angles(-vector.z,0,-vector.x)
else
root.RootJoint.C0 = CFrame.new(0,-vector.z * 1.25,0,-1,0,0,0,0,1,0,1,0) * CFrame.Angles(-vector.z,0,-vector.x)
end
end)