How to make a character as a friend of the player?

  1. What do you want to achieve? a character as a friend of the player

  2. What is the issue? it doesnt work, but prints everything by the first and last line of code

  3. What solutions have you tried so far? every single yt video and forum

also, i got every friend userID in my table, but wont create a model like one of those

local Players = game:GetService("Players")
local player = Players.PlayerAdded:Wait()
local friends = Players:GetFriendsAsync(player.UserId)

local ids = table.create(200)
local count = 0

while true do
	for _, item in ipairs(friends:GetCurrentPage()) do
		print(count, item.Id)
		count += 1
		ids[count] = item.Id
	end

	if friends.IsFinished then
		break
	end

	friends:AdvanceToNextPageAsync()
end

local randomFriendId = ids[math.random(1,count)]

local a = game:GetService("Players"):GetCharacterAppearanceAsync(ids[math.random(0,count)])


any idea why this doesnt work or maybe you have a code that can do what im asking?

This function is deprecated, meaning it doesn’t work properly anymore, try using

a = game:GetService("Players"):CreateHumanoidModelFromUserId(ids[math.random(0,count)])

Remember to parent a to workspace or else it won’t show up

a.Parent = workspace