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

How would I add a character model using UserId in roblox?[SOLVED] :D

This plugin: https://www.roblox.com/library/752585459/Load-Character-Lite Asks for the player's name, then converts it to UserId, but I do not know where to go from there. I thought there was a simple function like :GetCharacterAppearanceAsync, but that just spawns in the accessories.

Player = game.Players.LocalPlayer
ID = Player.UserId

CharacterTemplate = workspace.CharacterTemplate --part for CFrame
CharacterCFrame = CharacterTemplate.CFrame
Character = game.Players:GetCharacterAppearanceAsync(ID)
Character.Parent = workspace
Character:SetPrimaryPartCFrame(CharacterCFrame)
CharacterTemplate:Destroy()

The script gets the localplayer, spawns it in, and deletes the CFrame part - all on the clients end, but it "just spawns in the accessories"

4 comments

0

Players:GetCharacterAppearanceInfoAsync

0

Oh

0

Found InsertService:LoadAsset to load everything in, it says "You can use InsertService:LoadAsset to load the assets that are used in the player’s avatar"

0

Thanks

1 answer

Solution

In fact, can get the character using an in- build function, or two lines of code taken fro Link 1:

local Appearance = Players:GetHumanoidDescriptionFromUserId(UserID)
Dummy.Humanoid:ApplyDescription(Appearance)

You need a dummy, and UserID, which is way simpler than I expected. I made a function that accepts PlayerID, Player, PlayerName, and Character, then applies it to the dummy. See Link 2, and the discussion why :ApplyDescription() is only available on server scripts

function - made easy for beginners

--[[
ApplyCharacter([PlayerID, Player, PlayerName, Character], Dummy)

[] = list of options

Examples using user - Defaultio: 
UserID - 1320922
	
UserName - "Defaultio"
	
Character - workspace:FindFirstChild("Defaultio")
	
Player - game.Players:FindFirstChild("Defaultio")

This function cannot work in a local script, or you will get the following error:
"Humanoid::ApplyDescription() can only be called by the backend server"

If no Player is found it will return nil, otherwise it will return the UserID
You never know if this will be useful ^

Choose R15 or R6 using the Rig builder(Under plugins) to make the dummy, then remove both of the face decals found in the head part, however if the person doesent have a purchased face equipped(smiley) then they need to stay.

--]]
function ApplyCharacter(Input, Dummy)
	local Success
	local ErrorMessage
	if Dummy and Dummy:FindFirstChild("Humanoid") then
		if Input then
			--if User ID
			if typeof(Input) == "number" then
				ID = Input
				Success, ErrorMessage = pcall(function()
					game.Players:GetCharacterAppearanceInfoAsync(ID)
				end)
			
			--if User Name
			elseif typeof(Input) == "string" then
				Success, ErrorMessage = pcall(function()
					ID = game.Players:GetUserIdFromNameAsync(Input)
				end)
			
			--If Input Object
			elseif typeof(Input) == "Instance" then
				
				--if Player
				Player, ErrorMessage = pcall(function()
					ID = Input.UserId
				end)
				if Player then Success = true end
	
				if not Player then
					
					--if Character
					Success, ErrorMessage = pcall(function()
						User = game.Players:GetPlayerFromCharacter(Input)
						ID = User.UserId
					end)
				end
			end
		end
		
		if Success then
			local Appearance = game.Players:GetHumanoidDescriptionFromUserId(ID)
			Dummy.Humanoid:ApplyDescription(Appearance)
			Dummy.Humanoid.DisplayName = game.Players:GetNameFromUserIdAsync(ID)
			return ID
		else
			if ErrorMessage == "Players:GetUserIdFromName() failed because the user does not exist" then
				game.TestService:Error("UserName " ..Input.. " does not exsist")
			elseif string.match(ErrorMessage, "does not exsist") then
				game.TestService:Error("UserName " ..Input.. " does not exsist")
			elseif ErrorMessage == "Players:GetCharacterAppearanceInfoAsync() failed because HTTP 400 (Bad Request)" then
				game.TestService:Error("UserID " ..Input.. " does not exsist")
			elseif string.match(ErrorMessage, "UserId is not a valid member of") then
				game.TestService:Error("Instance " ..Input.Name.. " Is not a valid Player or Character")
			elseif string.match(ErrorMessage, "attempt to index nil with 'UserId'") then
				game.TestService:Error("Instance " ..Input.Name.. " Is not a valid Player or Character")
			
			end
			return nil
		end
	end
end

Link1 https://devforum.roblox.com/t/how-to-get-a-players-entire-model-not-just-their-assets/421085


Link2 https://devforum.roblox.com/t/make-humanoid-applydescription-available-on-the-client/369092


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