Need help switching avatars for everyone in game

I need to make a in-game avatar the default avatar in my game, to make it so that it is still the player, but in like a rthro rig, only the appearance changes. (The rigs like human)

I have a orientation script(a script used to modify the position of a player), I want the script to work at the same time with my script for avatar swapping, the 2 scripts collide, I tried to make it so that the avatar swapping script finishes swapping the 2 avatars and than run the orientation script, the problem is, either the orientation script runs, or the avatar script runs.

I have tried the wait(1) to make the avatar script go first, but that just stops the orientation script, I have also named the rig “StarterCharacter” and put it in starter player, but that just stops the orientation script
Orientation Script:

local function applyOrientation(player)
    local character = player.Character
    if not character then return end

    local isMale = true
    local manModel = game.Workspace.ManModel:FindFirstChild("Man")
    local womanModel = game.Workspace.WomanModel:FindFirstChild("Woman")

    if not manModel or not womanModel then return end

    -- Tool Part
    local toolName = isMale and "ManM4A1" or "WomanM4A1"
    local tool = game.Workspace[isMale and "ManModel" or "WomanModel"]:FindFirstChild(toolName)
    if tool then
        for _, part in pairs(tool:GetDescendants()) do
            if part:IsA("BasePart") then
                part.Transparency = 0
            end
        end
    end

    -- Gender Verification
    if character:FindFirstChild("Humanoid"):GetAttribute("IsFemale") then
        isMale = false
    end
-- trying to copy and paste all the body parts from the models to the character
    for _, bodyPart in pairs(character:GetChildren()) do
        if isMale then
            local manBodyPart = manModel:FindFirstChild(bodyPart.Name)
            if manBodyPart then
                bodyPart.Orientation = manBodyPart.Orientation
                bodyPart.Position = manBodyPart.Position
            end
        else
            local womanBodyPart = womanModel:FindFirstChild(bodyPart.Name)
            if womanBodyPart then
                bodyPart.Orientation = womanBodyPart.Orientation
                bodyPart.Position = womanBodyPart.Position
            end
        end
        bodyPart.Anchored = true
    end

    character:SetPrimaryPartCFrame(CFrame.new(0, 0, 0))
    character.Anchored = true

--enabling canquery and cantouch
    for _, descendant in pairs(character:GetDescendants()) do
        if descendant:IsA("BasePart") then
            descendant.CanQuery = true
            descendant.CanTouch = true
        end
    end
end
wait(0.1)
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        applyOrientation(player)
    end)
end)
-- the end of the script .

Avatar Script:

local Players = game:GetService("Players")

local function switchToDefaultAvatar(player)
	local defaultAvatar = game.Workspace:FindFirstChild("Default")
	if defaultAvatar then
		local clone = defaultAvatar:Clone()

		for _, part in pairs(clone:GetDescendants()) do
			if part:IsA("BasePart") then
				part.CanQuery = true
				part.CanTouch = true
			end
		end


		if player.Character then
			player.Character:Destroy()
		end


		clone.Parent = game.Workspace
	end
end

Players.PlayerAdded:Connect(switchToDefaultAvatar)

-- Handle players who are already in the game
for _, player in ipairs(Players:GetPlayers()) do
	switchToDefaultAvatar(player)
end

I need it so that these 2 scripts will function without colliding (Avatar script first than Orientation script)
Really need help
Thanks.

1 Like