Certainly! If you want to reference the players via the Players service instead of workspace, you can do so, but note:
- Typically, player characters live as Models inside
workspace — The Players service itself contains Player instances, but the actual character models are usually children of workspace.
- So to get the character models, you get
Players.Player.Character (which refers to the model in workspace).
Here’s how you can modify the script to get the character models of players from the Players service.
Updated Script Using Players service:
local Players = game:GetService("Players")
-- Replace these names with actual player user names or whatever identifiers you use
local specifiedPlayerName = "SpecifiedPlayerName"
local altPlayerNames = {
"AltPlayer1Name",
"AltPlayer2Name",
"AltPlayer3Name",
"AltPlayer4Name",
"AltPlayer5Name"
}
-- Helper to get player's Character CFrame safely
local function getCharacterCFrame(playerName)
local player = Players:FindFirstChild(playerName)
if player and player.Character and player.Character.PrimaryPart then
return player.Character.PrimaryPart.CFrame, player.Character
else
return nil, nil
end
end
-- Get specified player CFrame and Character
local baseCFrame, specifiedCharacter = getCharacterCFrame(specifiedPlayerName)
if not baseCFrame then
warn("Specified player character not found or has no PrimaryPart")
return
end
-- Get altplayer characters
local altChars = {}
for i, name in ipairs(altPlayerNames) do
local _, char = getCharacterCFrame(name)
if char then
altChars[i] = char
else
warn("Alt player '"..name.."' character not found or no PrimaryPart")
altChars[i] = nil
end
end
-- Degrees to radians converter
local function degToRad(deg)
return deg * math.pi / 180
end
-- Calculating altplayer1 rotation with pitch=90 and roll=90
local pitch90 = CFrame.Angles(degToRad(90), 0, 0)
local roll90 = CFrame.Angles(0, 0, degToRad(90))
local baseRotation = CFrame.new() * (baseCFrame - baseCFrame.Position)
local alt1Rotation = baseRotation * pitch90 * roll90
-- Calculate altplayer1 position (3 studs down Y axis)
local alt1Pos = baseCFrame.Position + Vector3.new(0, -3, 0)
-- Function to get height of model or part for stacking
local function getHeight(model)
if model:IsA("BasePart") then
return model.Size.Y
elseif model:IsA("Model") then
local _, size = model:GetBoundingBox()
return size.Y
else
return 0
end
end
-- Apply transforms to altplayer1, 2, 3 (if they exist)
if altChars[1] and altChars[1].PrimaryPart then
altChars[1].PrimaryPart.CFrame = CFrame.new(alt1Pos) * alt1Rotation
end
if altChars[2] and altChars[2].PrimaryPart then
local alt2Pos = alt1Pos + alt1Rotation.RightVector * 5
altChars[2].PrimaryPart.CFrame = CFrame.new(alt2Pos) * alt1Rotation
end
if altChars[3] and altChars[3].PrimaryPart then
local alt3Pos = alt1Pos - alt1Rotation.RightVector * 5
altChars[3].PrimaryPart.CFrame = CFrame.new(alt3Pos) * alt1Rotation
end
-- For altplayer4 and altplayer5, stack on top of specified player
local specifiedHeight = getHeight(specifiedCharacter)
local alt4Height = altChars[4] and getHeight(altChars[4]) or 0
local alt5Height = altChars[5] and getHeight(altChars[5]) or 0
-- Position altplayer4 on top of specified player
if altChars[4] and altChars[4].PrimaryPart then
local alt4PosY = baseCFrame.Position.Y + specifiedHeight / 2 + alt4Height / 2
local alt4Pos = Vector3.new(baseCFrame.Position.X, alt4PosY, baseCFrame.Position.Z)
altChars[4].PrimaryPart.CFrame = CFrame.new(alt4Pos) * baseRotation
end
-- Position altplayer5 stacked on altplayer4
if altChars[5] and altChars[5].PrimaryPart then
local alt4PosY = baseCFrame.Position.Y + specifiedHeight / 2 + alt4Height / 2
local alt5PosY = alt4PosY + alt4Height / 2 + alt5Height / 2
local alt5Pos = Vector3.new(baseCFrame.Position.X, alt5PosY, baseCFrame.Position.Z)
altChars[5].PrimaryPart.CFrame = CFrame.new(alt5Pos) * baseRotation
end
What you need to do:
- Replace
"SpecifiedPlayerName" with the actual player user name of the player you want to match.
- Replace the alt player names with the usernames.
- Your player characters must have a PrimaryPart assigned (usually
HumanoidRootPart).
- This script moves their PrimaryPart CFrame; this will move the entire character model accordingly.
If you want to move whole models, make sure PrimaryPart is set properly, otherwise you can try moving the whole model via SetPrimaryPartCFrame.
Let me know if you'd like me to help you customize it further!