Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can't seem to get the ID of the player?

I'm trying to make the model that looked like the player when they joined. But I can't seem to work it out.

local player = game:GetService("Players"):GetPlayerByUserId(1)
local Models = game.Players:GetCharacterAppearanceAsync(player)

game.Players.PlayerAdded:Connect(function(player)
	Models.Parent = script.Parent
	wait()
	for i,v in pairs(Models:GetChildren()) do
		print(v.Name)
		v.Parent = script.Parent
		wait()
	end
end)

1 comment

0

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.

1 answer

✓ 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!

2 comments

0

Ah! I was about to answer but realized you already had and that yours was far superior than mine. I gave you an upvote :)

0

Thank you, it very works. I'll try to understand the solution bit futher.

This discussion is preserved as it was. New answers, comments, and votes are closed.