How Do I Change A Players Avatar?

Hey there so I’m making a script where I will be changing the players avatar to either Dev which is me or Built who is my builder. The events work and all because the player does become the Parent of the Character. How can I make it so the player morphs into the Character from here?

local ReplicatedStorage = game:GetService("ReplicatedStorage")

ReplicatedStorage.Events.DevChosen.OnServerEvent:Connect(function(player)
	local Characters = ReplicatedStorage.Characters
	local character = Characters.Developer4Lifee:Clone()
	character.Parent = player
end)
ReplicatedStorage.Events.BuiltChosen.OnServerEvent:Connect(function(player)
	local Characters = ReplicatedStorage.Characters
	local character = Characters.Being_Built:Clone()
	character.Parent = player
end) 

The characters are models so I’m wondering if i’d need to ungroup them at all?
image

1 Like

You don’t parent the character model to the current character. Try this:

-- Note: This is only usable in a LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

function morphCharacter()
    local charactersFolder = ReplicatedStorage:WaitForChild("Characters")

    local player: Player = Players.LocalPlayer
    local character: Model = player.Character
    local morph: Model = charactersFolder.Whoever
    local morphClone = morph:Clone()

    local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")
    local morphHumanoidRootPart = morphClone:WaitForChild("HumanoidRootPart")

    morphHumanoidRootPart.CFrame = HumanoidRootPart.CFrame -- put the morph in wherever your character currently is
    morphClone.Name = player.Name -- name for the player
    player.Character = morphClone -- sets the character model to the morph
    morphClone.Parent = workspace
end
1 Like

So should I edit my current local script for my UI and add that function when the choose button is clicked? Will this also show your avatar as changed for every other player on server?

You can do that. Just use one LocalScript, don’t add one per button. Also, first check if that script works.

And

No, I wrote this as part of a LocalScript, meaning changes are only visible to the client. For that, you would want to use a RemoteEvent (and a Server-sided script) instead.

Dont worry script works and I am using one LocalScript. Also can u check my edit of my previous reply?

You would want to try this instead:

-- LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote_morph = ReplicatedStorage:WaitForChild("Insert_Your_Remote_Name_Here")
local button = "" -- Insert your button here

button.Activated:Connect(function()
    local morph = "" -- Insert your morph here
    Remote_morph:FireServer(morph)
end)

-- ServerScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Remote_morph = ReplicatedStorage:WaitForChild("Insert_Your_Remote_Name_Here")

Remote_morph.OnServerEvent:Connect(function(player, morph)
    local charactersFolder = ReplicatedStorage:WaitForChild("Characters")

    local player: Player = player
    local character: Model = player.Character
    local morph: Model = charactersFolder.Whoever
    local morphClone = morph:Clone()

    local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")
    local morphHumanoidRootPart = morphClone:WaitForChild("HumanoidRootPart")

    morphHumanoidRootPart.CFrame = HumanoidRootPart.CFrame
    morphClone.Name = player.Name
    player.Character = morphClone
    morphClone.Parent = workspace
end)
2 Likes