Code issues - AngularVelocity not a valid member of MeshPart

I’m developing a rotation system in Roblox Studio using Lua. When trying to apply the AngularVelocity property to MeshPart objects within my script, I receive the following error: ‘AngularVelocity is not a valid member of MeshPart’. I need help understanding why this is happening and how I can fix it to achieve the desired rotation on my MeshPart objects.

image

code server-side

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ToggleSwitch = ReplicatedStorage:WaitForChild("ToggleSwitch")
local stopRotationEvent = ReplicatedStorage:WaitForChild("StopRotationEvent")

local floorAreaModel = game.Workspace.FloorArea

local isRotating = false

local function rotatePart(part, rotationSpeed, rotationDirection)
	local angularVelocity = Vector3.new(0, 0, 0)
	if rotationDirection == "left" then
		angularVelocity = Vector3.new(0, rotationSpeed, 0)
	elseif rotationDirection == "right" then
		angularVelocity = Vector3.new(0, -rotationSpeed, 0)
	end
	part.Anchored = false
	part.AngularVelocity = angularVelocity
end

ToggleSwitch.OnServerInvoke = function(player, selectedButtons)
	print("Received remote function call from player:", player.Name)
	print("Selected buttons received from client:")
	print(selectedButtons)

	isRotating = true

	-- Define the rotation speed
	local rotationSpeed = 90 -- 90 degrees per second

	-- Determine rotation direction
	local rotationDirection = nil
	for _, button in ipairs(selectedButtons) do
		if button.rotation then
			rotationDirection = button.rotation
			break
		end
	end

	if rotationDirection then
		-- Rotate the objects F1, F2, and F3 if they are active
		for _, button in ipairs(selectedButtons) do
			if button.model == "F1" or button.model == "F2" or button.model == "F3" then
				local part = floorAreaModel[button.model]
				print("Rotating", button.model, "in direction:", rotationDirection)
				rotatePart(part, rotationSpeed, rotationDirection)
			end
		end
	else
		print("No rotation direction specified.")
	end

	print("Rotation operations completed.")

	-- Return an optional value if necessary
	return "Rotation operations completed"
end

stopRotationEvent.OnServerEvent:Connect(function(player)
	isRotating = false
	-- Stop the rotation of all objects F1, F2, and F3
	for _, partName in ipairs({"F1", "F2", "F3"}) do
		local part = floorAreaModel[partName]
		part.Anchored = true
		part.AngularVelocity = Vector3.new(0, 0, 0)
	end
end)

MeshParts don’t have a property named AngularVelocity, but they do have one named AssemblyAngularVelocity which seems to be the property you need

Essentially, wherever you’ve written:

part.AngularVelocity

must be replaced with

part.AssemblyAngularVelocity

to fix the problem

1 Like

Thank you very much. The problem is that the object rotates and moves then stop rotating. How can I make it anchored fixed in its position and rotate there?

If you wish to rotate a part using physics (and without the part moving around like in the clip you provided), then I recommend using a HingeConstraint to do so instead of setting its AssemblyAngularVelocity

Maybe do MeshPart:ApplyAngularImpulse?