Ad
Log in to vote
0

Making Character Model Match Local Player?

Asked by 3 years ago

Hello, I'm quite a experienced scripter, yet I am struggling in how to make a blank player model in the game's workspace match the player locally.

I've tried cloning the player's clothes and placing them into the model (local script) But I can't figure out how to get the hats and all that stuff, and for using it in a custom character script, I dont know what to do so it constantly matches the player, other than changing the model locally seperate

1 answer

Log in to vote
1
Answered by
Unhumanly 152
3 years ago
Edited 3 years ago

There's a function of the Players service. It's called GetCharacterAppearanceAsync.

The function returns a model containing all of the assets that a player(you need to put their UserId for the parameter) is wearing, except for their gear.

If you don't want a model, but a table instead, you can use GetCharacterAppearanceInfoAsync, which does the same, but returns a table.

local Model = game.Players:GetCharacterAppearanceAsync(13645)

The code above would return a model, containing all of the assets that Telamon is currently wearing.

This(as far as I'm aware) includes the shirt, the pants, the T-shirt, any accessories, and any body parts that the player is wearing.

We can then simply parent any shirt, pants, T-shirt, or CharacterMesh that the model has to the clone.

When using the AddAccessory function of Humanoid, make sure that there is an Attachment of each type(you may not remember which accessories require which attachments) that are descendants of the clone. If you don't do this, then the accessory won't be attached to the clone(from my understanding of the Developer Hub).

local Model = game.Players:GetCharacterAppearanceAsync(13645)
local Dummy = game.Workspace.Dummy

for i, v in pairs(Model:GetChildren()) do
    if v.ClassName == "Shirt" or v.ClassName == "Pants" then
        v.Parent = Dummy
    elseif v.ClassName == "Accessory" then
        Dummy.Humanoid:AddAccessory()
    elseif v.ClassName == "CharacterMesh" then
        v.Parent = Dummy
    end
end

I know that you don't need to add that last elseif statement(as opposed to putting it in the first conditional statement), but I did so the code block doesn't automatically drop a line

Looking at this, it looks like it should work. I know you wanted to make a clone of YOUR character, but this should work just the same if you put the LocalPlayer's UserId in the function.

If anyone spots out an error (or more) I've made, please point it out.

Ad

Answer this question