How can I create a max rotation speed for a levitating part?

I’m trying to limit the max rotation speed of a cube. Players need to survive on the cube for a limited time, but if unanchored parts on the cube weight too much, the cube starts to spin very fast, which is bad since the players cannot survive on a cube like that. Video of gameplay below.

The way the cube is built is all the parts are welded together, and in the middle there is a core. That core is attached with a UniversalConstraint to an anchored part.

This is the code that I’ve tried using, it works when there isn’t that many unanchored parts, but it fails if there is too much pressure and the cube starts to spin really fast. You can see the sudden speed change when all the parts fell off.

local MAX_SPEED = 0.1 --This number seems to work good for a max speed
RService.Stepped:Connect(function()
	local AngVel = module.Core.AssemblyAngularVelocity --gets the speed of the core
	local RotSpeed = math.sqrt(AngVel.X^2+AngVel.Y^2+AngVel.Z^2) --Pythagoras' theorem to get the speed but in a single float
	if RotSpeed > MAX_SPEED then -- Sets the Rotation speed if too high.
		module.Core.AssemblyAngularVelocity = AngVel / (RotSpeed / MAX_SPEED)
	end
end)

I’ve looked for a solution here on the dev forum, but did not find any.

The issue is you’re setting the velocity directly to the part. This gets influenced by external factors and is generally not a good way of doing it if you want a constant rotation. Its made worse that you’re applying it before the physics engine itself has done its own calculations that step.

Consider AngularVelocity since that applies a constant velocity rather than just an initial one.

I will try to make a script with AngularVelocity, if everything goes well I will set this as the solution.

Nope, I cannot come up with a way that would work. Can you help me with the script? I have no idea how to calculate what the MaxTorque of the AngularVelocity should be set to.