Certainly! To make the wheel match both the position and rotation (orientation) of the SpecifiedPlayer, we need to:
- Use the
SpecifiedPlayer's HumanoidRootPart CFrame as a reference.
- Calculate the AltPlayers' positions relative to that CFrame (i.e., their offset positions should rotate along with the player).
- Keep the wheel spinning around the player while respecting their current facing direction.
What changes?
Instead of placing AltPlayers just around the SpecifiedPlayer's position on the XZ plane, we will:
- Use the
SpecifiedPlayer's HumanoidRootPart CFrame (which holds both position and rotation).
- Compute the offset vector from the player's CFrame basis vectors (right and look vector).
- Add the offset to the player's CFrame position and apply the rotation.
Updated script including rotation matching
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
-- Configuration
local specifiedPlayerName = "SpecifiedPlayerName" -- change this to the player's name
local altPlayersNames = { "AltPlayer1", "AltPlayer2", "AltPlayer3", "AltPlayer4", "AltPlayer5" } -- names of the AltPlayers
local radius = 10 -- radius of the wheel around the specified player
local spinSpeed = math.rad(30) -- radians per second, adjust for faster/slower spin
-- Get SpecifiedPlayer and AltPlayers instances
local specifiedPlayer = Players:FindFirstChild(specifiedPlayerName)
if not specifiedPlayer or not specifiedPlayer.Character or not specifiedPlayer.Character:FindFirstChild("HumanoidRootPart") then
warn("SpecifiedPlayer or their HumanoidRootPart not found.")
return
end
local altPlayers = {}
for _, name in ipairs(altPlayersNames) do
local altPlayer = Players:FindFirstChild(name)
if altPlayer and altPlayer.Character and altPlayer.Character:FindFirstChild("HumanoidRootPart") then
table.insert(altPlayers, altPlayer)
else
warn("AltPlayer "..name.." or their HumanoidRootPart not found.")
end
end
if #altPlayers < 5 then
warn("Not all AltPlayers are valid.")
-- You can decide to stop here or continue with those found
end
-- Calculate initial angles for the 5 altplayers spaced evenly
local numAltPlayers = #altPlayers
local angleBetween = (2 * math.pi) / numAltPlayers
local angles = {}
for i = 1, numAltPlayers do
angles[i] = (i - 1) * angleBetween
end
-- Spin function
local currentAngle = 0
RunService.Heartbeat:Connect(function(dt)
if not specifiedPlayer.Character or not specifiedPlayer.Character:FindFirstChild("HumanoidRootPart") then
-- Player left or respawned
return
end
local hrp = specifiedPlayer.Character.HumanoidRootPart
local baseCFrame = hrp.CFrame
currentAngle = currentAngle + spinSpeed * dt
for i, altPlayer in ipairs(altPlayers) do
if altPlayer.Character and altPlayer.Character:FindFirstChild("HumanoidRootPart") then
local angle = currentAngle + angles[i]
-- Compute offset relative to player orientation:
-- offset on player's right vector (X) and look vector (Z)
local offset = Vector3.new(math.cos(angle) * radius, 0, math.sin(angle) * radius)
-- Transform offset from local space to world space using baseCFrame's rotation (ignoring Y component for now)
local worldPos = baseCFrame.Position + (baseCFrame.RightVector * offset.X) + (baseCFrame.LookVector * offset.Z)
local altHrp = altPlayer.Character.HumanoidRootPart
-- Position the altPlayer's HumanoidRootPart at worldPos, maintain the original Y height
altHrp.CFrame = CFrame.new(worldPos.X, altHrp.Position.Y, worldPos.Z)
-- Optionally, make AltPlayers face forward along their tangent direction on the wheel
-- Calculate tangent direction (derivative of circle)
local tangentLocal = Vector3.new(-math.sin(angle), 0, math.cos(angle))
-- Transform to world space
local tangentWorld = (baseCFrame.RightVector * tangentLocal.X) + (baseCFrame.LookVector * tangentLocal.Z)
tangentWorld = tangentWorld.Unit
-- Set orientation so AltPlayers face along tangent direction
altHrp.CFrame = CFrame.new(worldPos.X, altHrp.Position.Y, worldPos.Z, tangentWorld.X, 0, tangentWorld.Z)
end
end
end)
Explanation:
- We get the
baseCFrame (position and rotation) of the specified player's HumanoidRootPart.
- Compute
offset vectors around a circle in the player's local XZ plane.
- Transform those offsets to the world space by combining the player's
RightVector and LookVector.
- AltPlayers are moved to those calculated positions.
- AltPlayers are rotated to face along the tangent of the circle (makes them look like they're "spinning" properly).
Let me know if you want the AltPlayers to also move vertically relative to the specified player (e.g., matching Y position exactly), or have other behaviors!