Hello. I have been trying to figure out how I would go about changing the player’s avatar when I click a button, but I couldn’t find anything to help me out. I have a model that will work for the character (I know this because it works when I put it as the starter character).
You can use the HumanoidDescription System to change their avatar by applying it to the character’s Humanoid using Humanoid:ApplyDescription to set it, and Humanoid:GetAppliedDescription to get it if you want to modify the existing one (then you will have to set it after modifying it).
If you want to make them look like someone else, you can use Players:GetHumanoidDescriptionFromUserId.
Thanks! Unfortunately, I seem to be getting an error. Could you tell me what I am doing wrong?
Code
impersonate.MouseButton1Click:Connect(function()
local userId = game.Players:GetUserIdFromNameAsync(user.Text)
local humDesc = game.Players:GetHumanoidDescriptionFromUserId(userId)
game.Players.LocalPlayer.Character.Humanoid:ApplyDescription(humDesc)
end)
Error:
Humanoid::ApplyDescript() can only be called by the backend server
You can only use the humanoiddescription system from a server script, not a localscript
Aw really? There’s not a way I could do it from the client?
It’s inaccessible to the client for security reasons i suppose
Are you using a gui to change the player’s avatar?
Yeah, I am using a gui to change the player’s avatar.
In that case i recommend you do this
- upon impersonate.MouseButton1Click event firing, fire a remote event containing the userid you want in the fireserver argument
- Have the server read the userid argument on a .OnServerEvent connection and use GetHumanoidDescriptionFromUserId(userId) on that userid
- Apply the humanoiddescription that you got to the player’s character’s humanoid(the player who fired is always the first arg in a .OnServerEvent so you can get their character from there)
You can just use RemoveEvents.
You can, if you create a humanoid locally.
Try destroying humanoid from client and recreate it.
impersonate.MouseButton1Click:Connect(function()
game.Players.LocalPlayer.Character.Humanoid:Remove()
Instance.new("Humanoid").Parent = game.Players.LocalPlayer.Character
local userId = game.Players:GetUserIdFromNameAsync(user.Text)
local humDesc = game.Players:GetHumanoidDescriptionFromUserId(userId)
game.Players.LocalPlayer.Character.Humanoid:ApplyDescription(humDesc)
end)
I was not aware that it was available for clients to use now for local rigs. But OP is trying to use it on their own character which i’m not sure if it works or not.
Using this method and the provided code, I die instantly and respawn with my old avatar.
I’ve found a new method! Borrowing some code from a plugin, I’ve got a way to load the character into the game. This is my new code:
impersonate.MouseButton1Click:Connect(function()
local e = bruh(user.Text, workspace, morph == "R15" and true or false)
e.Parent = workspace
e.Humanoid.NameDisplayDistance = 0
e.HumanoidRootPart.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame
game.Players.LocalPlayer.Character = e
game.Workspace.Camera.CameraSubject = e.Head
end)
Although, when I do this, everything but the animations works. The animations script is in my model, but nothing is being animated. Do you have any idea how I can make the animations work?
Ohh i see,
Use remote events then.
Create a RemoteEvent in ReplicatedStorage (or any where you want)
Create a server script and type the following
Server Script
local event = game.ReplicatedStorage.RemoteEvent -- Our event
event.onServerEvent:Connect(function(player,user) -- When event is triggered [stores player and the user text]
local userId = game.Players:GetUserIdFromNameAsync(user)
local humDesc = game.Players:GetHumanoidDescriptionFromUserId(userId)
player.Character.Humanoid:ApplyDescription(humDesc)
end)
Your local script
local event = game.ReplicatedStorage.RemoteEvent
impersonate.MouseButton1Click:Connect(function()
event:FireServer(user.Text)
end)
As I said before, I have found a method to get the model in. I now just need help with getting the animations to work.
Well, just replace it with this one.
because the one i gave you have no animation issue.
But that method involves me using RemoteEvents. I don’t want it to replicate on the server.
Oh, I see.
Make sure the animate script should be a local script and must be inside the model.
Yeah, it is both inside the player model as well as a local script.