Hello! I would like to make the player be affected by the physics of the rotating system, how could I do that?
server-side script:
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
-- Modify the rotatePart function to apply cumulative rotation
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)