✓ Accepted answer
Problem
GetPlayerByUserId finds and returns the Player instance. If the player with that ID is not found in your game, it returns false. In other words, your chunk of code at line 1 won't work unless a player with the ID of 1 joins.
GetCharacterAppearanceAsync takes a UserId (number) for its first argument. You're putting in *player *which is an instance.
Solution
Your logic is a bit off. You should be using the player parameter in your function connected to the PlayerAdded event at line 04 to be getting the player's appearance.
Accessories need to be attached to the character to actually look like an accessory. This is easily done by a function of humanoid named AddAccessory.
When a Player joins, iterate through the Appearance model that GetCharacterAppearanceAsync returns and equip it to say rig; if the value's ClassName is equal to Accessory - use the AddAccessory method of Humanoid to equip it, else, Parent it to the rig.
local figure = workspace.Dummy
local figure_humanoid = figure.Humanoid
game.Players.PlayerAdded:Connect(function(player)
local appearance = game.Players:GetCharacterAppearanceAsync(player.UserId)
for _, v in pairs(appearance:GetChildren()) do
print(v, v.ClassName)
if v.ClassName == "Accessory" then
figure_humanoid:AddAccessory(v)
elseif v.Name == "face" then
v.Parent = figure.Head
else
v.Parent = figure
end
end
end)
Dummy Hierarchy in workspace.
Hope this helped!
1 comment
You can't get the model because there isn't a player in the game with the user ID of 1. The way the function works is it checks to see if there's a player in the players service that has a user ID of the one you provided, and if there is, return that player. If there isn't return nil, which is what is being done here, since you definitely aren't Roblox.