Certainly! Below is a Lua script for Roblox that makes five "altplayers" (altplayer1, altplayer2, altplayer3, altplayer4, altplayer5) orbit around a specified player with the configurations you requested:
- Orbit speed varying from 7 to 25.
- Orbit radius varying from 9 to 27.
- The altplayers orbit vertically from 9 studs above to 9 studs below the specified player.
- The specified player's HipHeight will be set to 9, and WalkSpeed to 25.
Assumptions:
- The specified player is passed or defined as a
Player instance.
- The alts are model/character instances named
altplayer1 through altplayer5 in the workspace or accessible.
- This script should be run as a LocalScript or Script depending on your context (server or client).
- All altplayers have a HumanoidRootPart to move them around.
Script:
-- Configuration
local minSpeed = 7
local maxSpeed = 25
local minRadius = 9
local maxRadius = 27
local verticalOffsetTop = 9
local verticalOffsetBottom = -9
local altPlayersNames = {"altplayer1", "altplayer2", "altplayer3", "altplayer4", "altplayer5"}
-- Input: specify the player to orbit around
local Players = game:GetService("Players")
local specifiedPlayerName = "SpecifiedPlayerName" -- <-- Change this to the target player's name
local specifiedPlayer = Players:FindFirstChild(specifiedPlayerName)
if not specifiedPlayer or not specifiedPlayer.Character then
warn("Specified player not found or doesn't have a character")
return
end
local specifiedChar = specifiedPlayer.Character
local specifiedHRP = specifiedChar:FindFirstChild("HumanoidRootPart")
local specifiedHumanoid = specifiedChar:FindFirstChildOfClass("Humanoid")
if not specifiedHRP or not specifiedHumanoid then
warn("Specified player's Humanoid or HumanoidRootPart not found")
return
end
-- Set specified player's HipHeight and WalkSpeed
specifiedHumanoid.HipHeight = 9
specifiedHumanoid.WalkSpeed = 25
-- Function to get alt player character from workspace or Players
local function getAltCharacter(name)
local altChar = workspace:FindFirstChild(name)
if not altChar then
altChar = Players:FindFirstChild(name) and Players[name].Character
end
return altChar
end
-- Prepare alt players data
local altPlayers = {}
for i, name in ipairs(altPlayersNames) do
local char = getAltCharacter(name)
if char and char:FindFirstChild("HumanoidRootPart") then
table.insert(altPlayers, {
name = name,
character = char,
hrp = char.HumanoidRootPart,
speed = minSpeed + (maxSpeed - minSpeed) * ((i - 1) / (#altPlayersNames - 1)),
radius = minRadius + (maxRadius - minRadius) * ((i - 1) / (#altPlayersNames - 1)),
verticalDir = 1, -- 1 means going up, -1 means going down
verticalPosition = verticalOffsetBottom + (verticalOffsetTop - verticalOffsetBottom) * ((i - 1) / (#altPlayersNames - 1)),
angle = (2 * math.pi / #altPlayersNames) * (i - 1) -- start positions offset in radians
})
else
warn("Alt player "..name.." or its HumanoidRootPart not found.")
end
end
-- Orbit update loop
local RunService = game:GetService("RunService")
local verticalSpeed = 1 -- how fast the vertical position moves between -9 and 9 studs
RunService.Heartbeat:Connect(function(dt)
if not specifiedHRP then return end
local centerPos = specifiedHRP.Position
for _, alt in ipairs(altPlayers) do
-- Update angle based on orbit speed
alt.angle = alt.angle + alt.speed * dt
if alt.angle > 2 * math.pi then
alt.angle = alt.angle - 2 * math.pi
end
-- Update vertical position: ping-pong between verticalOffsetBottom and verticalOffsetTop
alt.verticalPosition = alt.verticalPosition + alt.verticalDir * verticalSpeed * dt
if alt.verticalPosition > verticalOffsetTop then
alt.verticalPosition = verticalOffsetTop
alt.verticalDir = -1
elseif alt.verticalPosition < verticalOffsetBottom then
alt.verticalPosition = verticalOffsetBottom
alt.verticalDir = 1
end
-- Calculate new position
local x = centerPos.X + alt.radius * math.cos(alt.angle)
local y = centerPos.Y + alt.verticalPosition
local z = centerPos.Z + alt.radius * math.sin(alt.angle)
local newPos = Vector3.new(x, y, z)
-- Move altplayer's HumanoidRootPart
alt.hrp.CFrame = CFrame.new(newPos, centerPos) -- look at player
end
end)
How to use:
- Replace
"SpecifiedPlayerName" with the actual player name you want the alts to orbit.
- Make sure the alt players (
altplayer1 through altplayer5) exist in the workspace or under Players with their characters loaded.
- Run this script on the server or client side as appropriate.
- Ensure the alt players can be moved by setting their HumanoidRootPart position / CFrame.
If you want me to tailor it to work inside a LocalScript or simplify it, or if your "altplayers" are something else (like custom NPCs models), please let me know!