Motor 6D spazzing out

I’m attempting to make a Power Up that spins on the ground. I am using Motor 6Ds to achieve this. The Power Up spins normally, until at a point when it just starts spazzing out for a few seconds, and then it will start spinning normally again. View the following recording:


By no means do I actually understand how Motor 6Ds work, I’m just trying to learn how to use them. Here is the code that I use:

local motor = Instance.new("Motor6D", model.PrimaryPart)
motor.Part0 = model.PrimaryPart
motor.Part1 = model:FindFirstChild("Container")
-- (unrelated filler)
self.spinConnection = RunService.Stepped:Connect(function() -- i used AI to generate this code :sob: im just trying to get it to work
	local position = motor.C1.Position
	local y = (tick() * SPIN_SPEED) % (2 * math.pi) -- spin speed is 0.5 in the video
	local _, _, z = motor.C1.Rotation:ToEulerAnglesXYZ()
	motor.C1 = CFrame.new(position) * CFrame.Angles(self.info.Tilt, y, z) -- tilt is math.rad(15) for the current Power Up
end)

If it should be useful, the way I organize the Power Ups is like so:

  1. A hitbox part (C0) with CanCollide set to true that acts as the collider for the Power Up (I have it set so it doesn’t collide with players via Collision groups.
  2. A container part (C1, which is literally a 0.001 xyz stud cube) that acts as the part that spins, all of the decorative parts are welded to this part, following the container.

The Y calculation is wrong, it’s a modulus operation. I’ve recreated it, and it worked fine after fixing:

local SPEED = 10
local TILT_X = 15
local TILT_Z = 0

game["Run Service"].Stepped:Connect(function(dt)
	motor.C1 = CFrame.new(motor.C1.Position) * CFrame.Angles(math.rad(TILT_X), math.rad(dt*SPEED), math.rad(TILT_Z))
end)

It works nicely, thank you. I figured out that just by making the Z coordinate to math.rad(0), it works fine, which you have also done. But this also helps with cleaning the code.