can you generate me a script that will make 5 altplayers orbit 1 specifiedplayer but 5 altplayers orbit plane will be rotated by 90 so it looks like a wheel and this wheel will also match rotation of specifiedplayer torso
Assistant
User
can it be isntead of primaryparts humanoidrootparts?
Assistant
Certainly! I assume you want a script in Roblox Lua that will make 5 "altplayers" (probably NPCs or parts representing other players) orbit around a "specifiedplayer" (a player instance), where the orbit forms a "wheel" shape with the orbit plane rotated by 90 degrees, and this wheel's rotation matches the specified player's torso rotation.
Key points:
5 altplayers orbit in a circle around the specified player's torso.
Orbit plane rotated by 90 degrees (so if normal orbit is in XZ plane, rotate to XY or YZ)
The entire orbit (wheel) rotates with the player's torso
The specified player has a Torso or UpperTorso (depending on R15 or R6) part accessible.
The 5 altplayers are NPC models or parts you control, you have references to their root parts (or their whole model).
You want the altplayers to move continuously around the player smoothly.
Script (ServerScript or LocalScript depending on usage):
lua
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
-- Configuration
local specifiedPlayer = Players:WaitForChild("PlayerNameHere") -- change to the username
local altPlayers = {
workspace:WaitForChild("AltPlayer1"),
workspace:WaitForChild("AltPlayer2"),
workspace:WaitForChild("AltPlayer3"),
workspace:WaitForChild("AltPlayer4"),
workspace:WaitForChild("AltPlayer5"),
}
local orbitRadius = 10
local orbitSpeed = math.rad(60) -- radians per second
local numAltPlayers = #altPlayers
local rotationOffset = math.rad(90) -- 90 degrees to rotate orbit plane
-- Utility: get player's torso part (works for R15 or R6)
local function getTorso(player)
local character = player.Character
if not character then return nil end
local torso = character:FindFirstChild("UpperTorso") or character:FindFirstChild("Torso")
return torso
end
-- Main
local angle = 0 -- orbital angle accumulator
RunService.Heartbeat:Connect(function(dt)
local torso = getTorso(specifiedPlayer)
if not torso then return end
-- Increase the orbit angle according to speed and dt
angle = angle + orbitSpeed * dt
local torsoCF = torso.CFrame
-- We want the orbit to be in a plane rotated 90 degrees -
-- normal orbit would be in XZ plane, now rotate so orbit is in YZ plane (for example)
-- Standard orbit position (on XZ plane):
-- x = radius*cos(theta)
-- z = radius*sin(theta)
-- y = 0
-- Rotate orbit plane by 90 degrees around X axis to put orbit in YZ plane:
-- So instead of (x, 0, z), points become (x, y, z) after rotation of 90 degrees about X axis:
-- Rotation 90 deg about X axis matrix:
-- [1 0 0]
-- [0 0 -1]
-- [0 1 0]
-- So a vector (x, y, z) becomes (x, -z, y)
-- Since y=0 in original orbit:
-- (x, 0, z) -> (x, -z, 0)
-- For each altplayer, calculate their position on orbit
for i, alt in ipairs(altPlayers) do
local a = angle + (2 * math.pi) * (i-1)/numAltPlayers -- spread evenly
local x = orbitRadius * math.cos(a)
local z = orbitRadius * math.sin(a)
local y = 0
-- Rotate 90 degrees about X axis:
local rotatedPos = Vector3.new(x, -z, y)
-- Now need to orient this by the torso's rotation so orbit plane matches torso rotation
-- We can multiply rotatedPos by the torso rotation:
local worldPos = torsoCF.Position + (torsoCF - torsoCF.Position).Vector3ToWorldSpace(rotatedPos)
-- Alternative to .Vector3ToWorldSpace (doesn't exist), correct approach is:
-- torsoCF is a CFrame, torsoCF.Position is Vector3
-- We want to apply torsoCF rotation (excluding translation) to rotatedPos
local rotatedWorldPos = torsoCF * rotatedPos
if alt:IsA("Model") and alt.PrimaryPart then
alt.PrimaryPart.CFrame = CFrame.new(rotatedWorldPos.Position)
elseif alt:IsA("BasePart") then
alt.CFrame = CFrame.new(rotatedWorldPos.Position)
end
end
end)
Important notes about the code above:
Replace "PlayerNameHere" with the actual player name or pass in a player object.
altPlayers array should contain references to the altplayer models or parts you want to orbit. Make sure each model has PrimaryPart set.
The orbit is calculated in a YZ plane instead of XZ plane (achieved by rotating the orbit plane by 90 degrees about X).
The orbit center follows the torso position and rotates with its rotation.
The rotation speed controls how fast the wheel spins.
You can adjust orbitRadius and orbitSpeed.
If you want the orbit plane rotated around Y instead of X, or a different axis, just rotate the plane accordingly or change the mapping.
Let me know if you want me to provide an example using Vector3 rotated by CFrame.Angles for rotating the orbit plane instead of manual rotation!
Absolutely! Using the HumanoidRootPart instead of PrimaryPart is often better for characters/models representing players/NPCs because the HumanoidRootPart is typically the main reference part for movement and positioning.
Here's the updated version with altplayers as models and their positions set relative to their HumanoidRootPart:
lua
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
-- Configuration
local specifiedPlayer = Players:WaitForChild("PlayerNameHere") -- change to the username
local altPlayers = {
workspace:WaitForChild("AltPlayer1"),
workspace:WaitForChild("AltPlayer2"),
workspace:WaitForChild("AltPlayer3"),
workspace:WaitForChild("AltPlayer4"),
workspace:WaitForChild("AltPlayer5"),
}
local orbitRadius = 10
local orbitSpeed = math.rad(60) -- radians per second
local numAltPlayers = #altPlayers
-- Utility: get player's torso part (works for R15 or R6)
local function getTorso(player)
local character = player.Character
if not character then return nil end
return character:FindFirstChild("UpperTorso") or character:FindFirstChild("Torso")
end
RunService.Heartbeat:Connect(function(dt)
local torso = getTorso(specifiedPlayer)
if not torso then return end
local angleStep = (2 * math.pi) / numAltPlayers
local time = tick() * orbitSpeed -- use tick to continuously spin
local torsoCF = torso.CFrame
for i, alt in ipairs(altPlayers) do
if alt:IsA("Model") then
local hrp = alt:FindFirstChild("HumanoidRootPart")
if hrp then
-- Calculate angle for this alt player
local a = time + angleStep * (i - 1)
-- Orbit on YZ plane (rotated 90 degrees about X axis)
local x = orbitRadius * math.cos(a)
local z = orbitRadius * math.sin(a)
local y = 0
-- Rotate 90 degrees about X: (x, 0, z) -> (x, -z, 0)
local rotatedPos = Vector3.new(x, -z, y)
-- Apply torso rotation (CFrame)
local worldPos = torsoCF * rotatedPos
-- Move HumanoidRootPart to worldPos
hrp.CFrame = CFrame.new(worldPos.Position) * CFrame.Angles(0, torsoCF.YOrientation * math.pi/180, 0)
-- Note: The additional rotation here to match torso yaw is optional,
-- torsoCF * rotatedPos already rotates correctly, so might remove above rotation
-- I'd recommend just:
-- hrp.CFrame = CFrame.new(worldPos.Position, torsoCF.Position)
-- so altplayers face center, or just positioning without rotation:
-- hrp.CFrame = CFrame.new(worldPos.Position)
end
end
end
end)
Explanation of key changes:
Used HumanoidRootPart (named "HumanoidRootPart") as the part moved for each alt player.
Continous rotation uses tick() multiplied by orbit speed to spin smoothly.
Orbit is still on YZ plane by rotating 90 degrees about the X axis.
Setting hrp.CFrame to new orbit position.
The rotation/orientation for the hrp is either aligned with the torso rotation or left as is; I left a comment for you to pick how you want it.
Optional orientation for the alt players:
If you want each alt player to face the specified player's torso as they orbit (like wheel spokes), replace the last line: