Hello! I'm including my code below. I basically want to be able to have a way for a rig to mimic a player. So if the player moves north, the rig will move north as well.
I've been attempting this all day and haven't managed to crack it. Below is my current attempt - anyone know how to deal with this or any advice?
local CollectionService = game:GetService("CollectionService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local character = script.Parent
-- Wait for character to load
if not character:FindFirstChild("Humanoid") then
character:WaitForChild("Humanoid")
end
-- Find the Copy rig
local tagged = CollectionService:GetTagged("Copy")
local copyRig = tagged[1]
-- If it doesn't exist yet, wait for it
if not copyRig then
copyRig = CollectionService:GetInstanceAddedSignal("Copy"):Wait()
end
if not copyRig then
warn("No Copy rig found!")
return
end
local copyHumanoid = copyRig:WaitForChild("Humanoid")
-- Copy animations
local animator = character.Humanoid:FindFirstChildOfClass("Animator")
local copyAnimator = copyHumanoid:FindFirstChildOfClass("Animator")
if animator and copyAnimator then
for _, track in animator:GetPlayingAnimationTracks() do
local copyTrack = copyAnimator:LoadAnimation(track.Animation)
copyTrack:Play()
-- Keep syncing when new animations play
track:GetPropertyChangedSignal("IsPlaying"):Connect(function()
if track.IsPlaying then
copyTrack:Play()
else
copyTrack:Stop()
end
end)
end
-- Handle new animations
animator.AnimationPlayed:Connect(function(track)
local copyTrack = copyAnimator:LoadAnimation(track.Animation)
copyTrack:Play()
track:GetPropertyChangedSignal("IsPlaying"):Connect(function()
if track.IsPlaying then
copyTrack:Play()
else
copyTrack:Stop()
end
end)
end)
end
-- Mirror jumping
character.Humanoid.StateChanged:Connect(function(oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then
copyHumanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
end)
-- Mirror movement and rotation using BindToRenderStep
-- This runs AFTER the character controls, so it won't be overwritten
RunService:BindToRenderStep(
"CopyRigMovement",
Enum.RenderPriority.Character.Value + 1,
function()
-- Copy the player's rotation first
local playerCFrame = character:GetPivot()
local copyCFrame = copyRig:GetPivot()
local newCopyCFrame = CFrame.new(copyCFrame.Position) * playerCFrame.Rotation
copyRig:PivotTo(newCopyCFrame)
-- Then apply movement in the same world direction as the player
local moveDirection = character.Humanoid.MoveDirection
if moveDirection.Magnitude > 0.01 then
-- Use the player's rotation to get world-space movement
local playerRotation = playerCFrame.Rotation
local worldMoveDirection = playerRotation:VectorToWorldSpace(moveDirection)
-- Apply that world direction to the copy
copyHumanoid:Move(worldMoveDirection, false)
else
-- Stop movement
copyHumanoid:Move(Vector3.zero, false)
end
end
)```
** You are now Level 1! **
