How To Fix The Players Camera Not On The Rig

Hi Developers so I need help with my morphing system for some odd reason the camera on my player doesnt replicate onto the rig so my camera is in the same position and isnt moving with the rig anyway to fix this and here is my code.

game.Players.PlayerAdded:Connect(function(plr)
    -- When a player joins the game, create variables to track their equipped character and owned characters
    local EquippedChar = plr:SetAttribute("Equipped", nil) -- Set the "Equipped" attribute to nil
    local OwnedChars = Instance.new("Folder", plr) -- Create a new folder to store owned characters
    OwnedChars.Name = tostring(plr.Name .. "Owned Characters") -- Set the name of the owned characters folder
end)

game.ReplicatedStorage["Buying Event"].OnServerEvent:Once(function(plr, Attribute)
    -- When the "Buying Event" is triggered on the server
    local CharactersFolder = game.ReplicatedStorage:FindFirstChild("CharactersFolder")
    -- Find the folder named "CharactersFolder" in the ReplicatedStorage

    if not CharactersFolder or not CharactersFolder:IsA("Folder") then
        -- If the CharactersFolder is not found or is not a folder, print an error message and return
        print("CharactersFolder not found or invalid")
        return
    end

    for i, Character in ipairs(CharactersFolder:GetChildren()) do
        -- Iterate through each child of the CharactersFolder
        if Character:IsA("Model") and Character.Name == Attribute then
            -- If the child is a Model and its name matches the requested character

            print("Character found:", Character.Name)

            local actualChar = CharactersFolder:FindFirstChild(tostring(Character.Name))
            -- Find the actual character model within the CharactersFolder

            local newChar = actualChar:Clone()
            -- Clone the actual character model to create a new instance

            local oldchar = plr.Character
            -- Store a reference to the player's current character

            newChar.Parent = workspace
            -- Set the new character as a child of the workspace

            newChar.Name = plr.Name
            -- Set the new character's name to the player's name

            newChar.HumanoidRootPart.Anchored = false
            -- Make sure the new character's root part is not anchored, allowing movement

            newChar:SetPrimaryPartCFrame(plr.Character.PrimaryPart.CFrame)
            -- Set the new character's position and orientation to match the player's current character

            plr.Character = newChar
            -- Set the player's character to the new character

            oldchar:Destroy()
            -- Destroy the player's previous character

            plr:SetAttribute("Equipped", newChar.Name)
            -- Set the "Equipped" attribute of the player to the name of the new character

            local OwnedFolder:Folder = plr:WaitForChild(plr.Name.."Owned Characters")
            -- Get a reference to the owned characters folder of the player

            local StringV = Instance.new("StringValue", OwnedFolder)
            -- Create a new StringValue instance within the owned characters folder

            StringV.Name = newChar.Name
            -- Set the name of the StringValue to match the new character's name

            break
            -- Exit the loop since the character has been found and processed
        end
    end
end)


1 Like