How to create players from the friendlist in roblox?

Hey there, I was wondering how I could create players from a player’s friendlist. I tried using ChatGPT and the documentation but ChatGPT is kinda stupid and the documentation won’t load. Anyways, if anybody knows how to do this and could provide some insight on it, I’d really appreciate that. I just need them to be recognised somewhere in the game so I can use them. Thanks in advance.

You can use Players:GetFriendsAsync(), using the UserId/user ID of the Player/player that you want to get the friends of. According to the documentations, the method returns a FriendPages object, which contains arrays with these fields:

  • Id, an int64, the friend’s user ID;

  • Username, a string, the current username of the friend;

  • DisplayName, another string, the friend’s Player.DisplayName/display name;

  • and IsOnline, a boolean, rather the friend is currently online or not.

Using the Id key, you can call Players:GetHumanoidDescriptionFromUserId() or Players:CreateHumanoidModelFromUserId() to get the friends’ HumanoidDescriptions or character models, respectively.

Creating Character Models & Loading HumanoidDescriptions

Since Players:CreateHumanoidModelFromUserId() returns a user’s character as whatever rig is it (R6 or R15), you may go with Players:CreateHumanoidDescriptionFromUserId() to just get the HumanoidDescription, which doesn’t include the rig type. If you do, and you do not already have a dummy to load the description (HumanoidDescription) to, you can use the Players:CreateHumanoidModelFromDescription() method; as the second parameter, this method takes a HumanoidRigType so that you can specify rather you want the rig to be R6 or R15.

Do not forget that if you already have a character model, you can use Humanoid:ApplyDescription()/Humanoid:ApplyDescriptionReset() on the character’s Humanoid. If you want to use these methods locally, the Humanoid will have to be created locally.

3 Likes

Could you give me an example of this?

Here’s a useful post I found for your case:

I’ll check it out tommorow, thanks!

1 Like

This is really helpful, but how could I clone a friend into the game? I tried all the syntax and methods I could think of but nothing came up.

You could use the following code to return a model of a specific person:

local FriendChar = Players:GetCharacterAppearanceAsync(player)

Then you’d need to find a way to apply those accessories to a default Rig.

Or if you prefer things to be in a table you could use this code snippet:

local CharacterAppearance = Players:GetCharacterAppearanceInfoAsync(player)

So I could do

local FriendChar = Players:GetCharacterAppearanceAsync(player)

local FriendCharClone = FriendChar:Clone()
FriendCharClone.Parent = workspace

?

Possibly, tell me if it works or not. I’ve never actually used that function.

It probably will though, if not just reply to me and tell me what’s no working.

It said unable to cast Instance to int64 at line line 64.

Oh I see now, replace this:

local FriendChar = Players:GetCharacterAppearanceAsync(player)

With this code:

local FriendChar = Players:GetCharacterAppearanceAsync(player.UserId)

I think I forgot to mention you don’t use the actual Player instance, you have to use their UserId.

My apologies, I mixed up two functions. Here is my ACTUAL code:

local function Player()
	local Friend = PlayersFriends[math.random(1, #PlayersFriends)]
	
	local FriendChar = Players:GetCharacterAppearanceAsync(Friend)

	local FriendCharClone = FriendChar:Clone()
	FriendCharClone.Parent = workspace
end

It now says unable to cast dictionary to int64, and here is my full code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServicePlayers = game:GetService("Players")

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local Char = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")

local MaxPopulation = Player:WaitForChild("MaxPopulation").Value
local CurrentPopulation = 0

local SpawnPoints = workspace.NPC_SPAWNS

local FriendsId = Player.UserId
local PlayersFriends = {}

local success, page = pcall(function() return Players:GetFriendsAsync(FriendsId) end)
if success then
	repeat
		local Info = page:GetCurrentPage()
		for i, v in pairs(Info) do
			table.insert(PlayersFriends, v)
		end
		if not page.IsFinished then 
			page:AdvanceToNextPageAsync()
		end
	until page.IsFinished
end

local function Player()
	local Friend = PlayersFriends[math.random(1, #PlayersFriends)]
	
	local FriendChar = Players:GetCharacterAppearanceAsync(Friend)

	local FriendCharClone = FriendChar:Clone()
	FriendCharClone.Parent = workspace
end
local function NPC()
	local NPC_LIST = {}
	for i, v in pairs(ReplicatedStorage.NPC_LIST:GetChildren()) do
		table.insert(NPC_LIST, v)
	end
	local Rand = NPC_LIST[math.random(1, #NPC_LIST)]
	local NPC = ReplicatedStorage.NPC_LIST:FindFirstChild(Rand.Name)
	NPC:Clone()
	NPC.Parent = workspace
end
while true do
	wait(1)
	if CurrentPopulation <= MaxPopulation then
		if math.random(1, 3) == 1 then
			Player()
		else
			NPC()
		end
	end
end

It also might not think PlayerFriends isn’t valid, or atleast the contents of it, because UserID doesn’t popup for autofill when I use Friend.UserID.

1 Like

Try getting the UserId from that player’s friend like this:

local UserId = game.Players:GetUserIdFromNameAsync(name)

But name also doesn’t appear with Friend.name, it seems like the whole “Friend” Variable is invalid.
Oh, and I got this:

  12:40:18.457  Players:GetUserIdFromNameAsync() failed: Unknown user  -  Client - LocalMapFans:34

and with the Friend.Name it gives

  12:40:55.003  Argument 1 missing or nil  -  Client - LocalMapFans:34

Maybe try “Friend.Username” I just went thru some documentation and found that. If that doesn’t work maybe try scouring the DevForum.

Also @Ovibion mentions that it’s “Friend.Username” too here:

Alright well I’m not getting errors anymore after that, and everything should work… but the player function doesn’t run or something? It looks like the player’s won’t appear. Should I add on anything to it, here is my code?:

local function Player()
	local Friend = PlayersFriends[math.random(1, #PlayersFriends)]
	
	local ID = Players:GetUserIdFromNameAsync(Friend.Username)
	local FriendChar = Players:GetCharacterAppearanceAsync(ID)

	local FriendCharClone = FriendChar:Clone()
	FriendCharClone.Parent = workspace
end

Try putting some print functions, then tell me which line isn’t working.

Edit: Also, is it at least being parented to workspace?

I think they all work. I put a print before and after each line and they all ran. Maybe it has to do with either 1. Display names or 2. Something to do with how I got the friends.

But is it in workspace? It may just because its parts are unanchored or it’s position is somewhere you can’t see.

Alright, that was the issue, thanks. It looks like they don’t anchor though, and I might be wrong but I don’t think they have bodyparts. Is there a way around this?