Certainly! Assuming you are working in a game or environment (such as Roblox, Unity, or another platform where scripting controls player characters), you want a script that makes an alternate player (let's call it altPlayer) constantly match the position of a specified player (let's call it targetPlayer).
I'll provide an example in Roblox Lua, as that's a common context for this kind of task. If you need a different platform, please specify.
Roblox Lua Script
This script assumes you have references to two players: the targetPlayer and the altPlayer. The script will constantly update the altPlayer character's position to match the targetPlayer's position every frame.
local Players = game:GetService("Players")
-- Replace these names with your actual player names or obtain them dynamically
local targetPlayerName = "Player1"
local altPlayerName = "AltPlayer1"
-- Get player objects
local targetPlayer = Players:FindFirstChild(targetPlayerName)
local altPlayer = Players:FindFirstChild(altPlayerName)
if not targetPlayer or not altPlayer then
warn("One or both players not found!")
return
end
-- Wait until both players have characters loaded
local function getCharacter(player)
while not player.Character or not player.Character:FindFirstChild("HumanoidRootPart") do
player.CharacterAdded:Wait()
end
return player.Character
end
local targetCharacter = getCharacter(targetPlayer)
local altCharacter = getCharacter(altPlayer)
local targetHRP = targetCharacter:WaitForChild("HumanoidRootPart")
local altHRP = altCharacter:WaitForChild("HumanoidRootPart")
-- Update altPlayer position every heartbeat
local RunService = game:GetService("RunService")
RunService.Heartbeat:Connect(function()
if targetHRP and altHRP then
altHRP.CFrame = targetHRP.CFrame
end
end)
How this works:
- The script first finds the two players by name.
- It waits for their characters to spawn and ensures their humanoid root parts exist.
- Every frame (Heartbeat event), it sets the alternate player's root part
CFrame to match the target player's, effectively cloning the position and orientation.
Important Notes:
- This script assumes both players have characters that are controllable.
- Overriding a player's character position constantly may conflict with player controls or physics.
- For a "copy position" effect without interfering with player control, consider using physics constraints or other methods.
Let me know if you want a script for another game engine or language!
Certainly! I'll expand the script to also include:
- altPlayer2, whose Head will match the position and orientation of altPlayer1's Head.
- Additionally, altPlayer2's Head will be rotated 90 degrees up relative to altPlayer1's Head orientation.
Explanation:
- We'll track
altPlayer1's Head CFrame.
- We'll set
altPlayer2's Head CFrame to altPlayer1's Head CFrame rotated 90 degrees upwards (which is a rotation of 90 degrees about the X-axis).
Complete Script:
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
-- Player names, replace as needed
local targetPlayerName = "Player1"
local altPlayer1Name = "AltPlayer1"
local altPlayer2Name = "AltPlayer2"
-- Get player objects
local targetPlayer = Players:FindFirstChild(targetPlayerName)
local altPlayer1 = Players:FindFirstChild(altPlayer1Name)
local altPlayer2 = Players:FindFirstChild(altPlayer2Name)
if not targetPlayer or not altPlayer1 or not altPlayer2 then
warn("One or more players not found!")
return
end
-- Helper function to get character and required parts
local function getCharacter(player)
while not player.Character or not player.Character:FindFirstChild("HumanoidRootPart") or not player.Character:FindFirstChild("Head") do
player.CharacterAdded:Wait()
end
return player.Character
end
local targetCharacter = getCharacter(targetPlayer)
local altCharacter1 = getCharacter(altPlayer1)
local altCharacter2 = getCharacter(altPlayer2)
local targetHRP = targetCharacter:WaitForChild("HumanoidRootPart")
local altHRP1 = altCharacter1:WaitForChild("HumanoidRootPart")
local altHead1 = altCharacter1:WaitForChild("Head")
local altHead2 = altCharacter2:WaitForChild("Head")
RunService.Heartbeat:Connect(function()
if targetHRP and altHRP1 and altHead1 and altHead2 then
-- 1. altPlayer1 position: match targetPlayer + 2 studs up
local targetCFrame = targetHRP.CFrame
local offset = Vector3.new(0, 2, 0)
altHRP1.CFrame = targetCFrame + offset
-- 2. altPlayer2 head position and orientation:
-- Get altPlayer1's Head CFrame
local headCFrame1 = altHead1.CFrame
-- Rotate 90 degrees up (about X axis)
local rotation90Up = CFrame.Angles(math.rad(90), 0, 0)
-- Apply the rotation
altHead2.CFrame = headCFrame1 * rotation90Up
end
end)
What this does:
- altPlayer1's HumanoidRootPart is positioned 2 studs above targetPlayer.
- altPlayer2's Head is positioned and oriented to exactly match altPlayer1's Head but rotated by 90 degrees upward (rotated around the X-axis).
- Rotation is done relative to altPlayer1's Head orientation, so it keeps the same location but turned 90° up.
Let me know if you want me to also match altPlayer2’s entire character position/orientation or handle other parts!
Certainly! I will extend the previous script to also include altPlayer3 whose head will:
- Match
altPlayer1's head position and orientation,
- Then be rotated 90 degrees left horizontally (i.e., about the Y-axis),
- And rotated 90 degrees up vertically (about the X-axis).
Important:
- Left horizontal rotation is a 90° rotation around the Y-axis (positive or negative depending on left/right).
- Up rotation is 90° around the X-axis.
- The two rotations can be combined by multiplying the two rotation CFrames.
Here is the updated script adding the described behavior for altPlayer3:
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
-- Player names, replace as needed
local targetPlayerName = "Player1"
local altPlayer1Name = "AltPlayer1"
local altPlayer2Name = "AltPlayer2"
local altPlayer3Name = "AltPlayer3"
-- Get player objects
local targetPlayer = Players:FindFirstChild(targetPlayerName)
local altPlayer1 = Players:FindFirstChild(altPlayer1Name)
local altPlayer2 = Players:FindFirstChild(altPlayer2Name)
local altPlayer3 = Players:FindFirstChild(altPlayer3Name)
if not targetPlayer or not altPlayer1 or not altPlayer2 or not altPlayer3 then
warn("One or more players not found!")
return
end
-- Helper function to get character and required parts
local function getCharacter(player)
while not player.Character or not player.Character:FindFirstChild("HumanoidRootPart") or not player.Character:FindFirstChild("Head") do
player.CharacterAdded:Wait()
end
return player.Character
end
local targetCharacter = getCharacter(targetPlayer)
local altCharacter1 = getCharacter(altPlayer1)
local altCharacter2 = getCharacter(altPlayer2)
local altCharacter3 = getCharacter(altPlayer3)
local targetHRP = targetCharacter:WaitForChild("HumanoidRootPart")
local altHRP1 = altCharacter1:WaitForChild("HumanoidRootPart")
local altHead1 = altCharacter1:WaitForChild("Head")
local altHead2 = altCharacter2:WaitForChild("Head")
local altHead3 = altCharacter3:WaitForChild("Head")
RunService.Heartbeat:Connect(function()
if targetHRP and altHRP1 and altHead1 and altHead2 and altHead3 then
-- 1. altPlayer1 position: match targetPlayer + 2 studs up
local targetCFrame = targetHRP.CFrame
local offset = Vector3.new(0, 2, 0)
altHRP1.CFrame = targetCFrame + offset
-- 2. altPlayer2 head position and orientation:
local headCFrame1 = altHead1.CFrame
local rotation90Up = CFrame.Angles(math.rad(90), 0, 0) -- 90 degrees up (X-axis)
altHead2.CFrame = headCFrame1 * rotation90Up
-- 3. altPlayer3 head:
-- 90 degrees left horizontally = +90 degrees around Y-axis
local rotation90Left = CFrame.Angles(0, math.rad(90), 0)
-- 90 degrees up vertically = 90 degrees around X-axis
-- Same as before
-- Apply rotations: rotation around Y first (left), then X (up)
altHead3.CFrame = headCFrame1 * rotation90Left * rotation90Up
end
end)
Summary of rotations for altPlayer3 head:
- First rotate 90 degrees left around Y axis.
- Then rotate 90 degrees up around X axis.
- Applied as:
headCFrame1 * rotation90Left * rotation90Up
Let me know if you want me to:
- Handle any smooth interpolation,
- Match other body parts,
- Or anything else!