My Part Isn't Rotating in Roblox Studio

Hi! Any idea why my part isn’t rotating? When I press “play” in Roblox Studio, nothing happens. What could be wrong?

script

local part = script.Parent

local angularVelocity = Vector3.new(0, math.rad(90), 0) 

while true do
	part.RotVelocity = angularVelocity
	wait() 
end
3 Likes

Hey, @PipeSader, Instead of your code try using this code, and I would recommend checking out the task library.

local part: Part = script.Parent

local angularVelocity = Vector3.new(0, math.rad(90), 0) 

while true do
	part.AssemblyAngularVelocity = angularVelocity
	task.wait() 
end

Hope this helps!
Have a great day!

3 Likes

Or just use

This works perfectly, but the issue is that the part isn’t rotating. What’s wrong?

1 Like

Uhm, very strange, when I run my code it does work. Can you send a picture of the script and the part or if you can can a video? Thanks @PipeSader

1 Like

Let me explain, what I would like to do in depth is to make the rotation that I am applying to my CFrames in my function also apply to the angular velocity so that when they rotate in CFrame, the angular velocity also rotates and affects the player’s physics, but I need them to be in sync in speed, and when ‘isRotatin’ is inactive (false), then also stop the angular velocity, but to be honest, I haven’t known how to implement it… any ideas?

this is the specific function code:

local function rotatePart(part, rotationSpeed, rotationDirection)
	while isRotatin do
		local delta = wait()
		local rotationAngle = math.rad(rotationSpeed * delta)
		if rotationDirection == "left" then
			part.CFrame = part.CFrame * CFrame.Angles(0, rotationAngle, 0)
		elseif rotationDirection == "right" then
			part.CFrame = part.CFrame * CFrame.Angles(0, -rotationAngle, 0)
		end
	end
end

this is my full code:

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

local floorAreaModel = game.Workspace.FloorArea

local F1_Part = floorAreaModel.F1
local F2_Part = floorAreaModel.F2
local F3_Part = floorAreaModel.F3

local isRotatin = false

local function rotatePart(part, rotationSpeed, rotationDirection)
	while isRotatin do
		local delta = wait()
		local rotationAngle = math.rad(rotationSpeed * delta)
		if rotationDirection == "left" then
			part.CFrame = part.CFrame * CFrame.Angles(0, rotationAngle, 0)
		elseif rotationDirection == "right" then
			part.CFrame = part.CFrame * CFrame.Angles(0, -rotationAngle, 0)
		end
	end
end

ToggleSwitch.OnServerInvoke = function(player, selectedButtons)
	print("Received remote function call from player:", player.Name)
	print("Selected buttons received from client:")
	print(selectedButtons)
	
	isRotatin = 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
		-- Create coroutines for rotating F1, F2, and F3 if they are active
		local coroutines = {}
		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)
				table.insert(coroutines, coroutine.create(function()
					rotatePart(part, rotationSpeed, rotationDirection)
				end))
			end
		end

		-- Start all coroutines
		for _, co in ipairs(coroutines) do
			coroutine.resume(co)
		end
	else
		print("No rotation direction specified.")
	end

	print("Rotation operations completed.")

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

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

stopRotationEvent.OnServerEvent:Connect(function()
	isRotatin = false
end)

and here is a video of the issue:

You could add a support part that rotates at the same speed as the main part and carries the player.

1 Like

Or is it possible to do it in a simpler way?

1 Like

I have an update, it’s not very advanced but maybe it could help.

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Part = game.Workspace.Part --Path to the part here
local RunService = game:GetService("RunService")

RunService.RenderStepped:Connect(function(dt)
	Part.CFrame *= CFrame.Angles(0,dt,0)
	Character.PrimaryPart.CFrame *= CFrame.Angles(0,dt,0)
end)

Hope it helps! Bye, @PipeSader

2 Likes

You can add an event like .Touched and then add the renderStepped.

2 Likes