Rotating a Ball Opposite where the Character Walks

I’m trying to have a ball rotate underneath the character opposite the direction they walk, sort of like a hamster wheel or a treadmill. I’m having problems with the rotation though, because the ball rotates relative to its own axes rather than an axis perpendicular to where the character is moving.

As long as the ball is oriented close to (0,0,0) it works:

18d5698283b9ee20cf41c4b9b66c98e9

However when the ball is rotated off center weird stuff starts happening like:

c1637847fd13cdba9591604022856303

I have a limited understanding of CFraming but I’ve spent the last couple days playing around and trying to come up with different ways of calculating the rotation, but none of them have worked.

Here is the present script (a local script in starterplayerscripts)

local plr = game.Players.LocalPlayer
local moon = workspace.moon
local c = moon.Size.X*math.pi
repeat wait() until plr.Character
local char = plr.Character

local function loop(dtime)
	moon.CFrame = CFrame.new(char.Torso.Position.X,0,char.Torso.Position.Z) * CFrame.Angles(-math.rad(char.Torso.Position.Z),0,math.rad(char.Torso.Position.X))
end

game:GetService("RunService").RenderStepped:Connect(loop)

Any help would be appreciated.

2 Likes