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: