I want to create a system where it randomly finds a friend of yours and creates a npc and parents then to a random part. I know i have to use :Getfriendsasync() but im not sure how to use it.
You will not be able to access any player’s avatar that is offline. However, you can do it if you’re familiar with HTTPService or other programming languages that would allow you to get the player’s avatar items.
I will give you a quick introduction, there is something called API, which is basically communication between applications, and in Roblox you can access the avatar items of a player even if they were offline. But depending on your coding experience that would take time and effort to achieve, APIs are so easy but sometimes HTTPService does not allow you to request from Roblox itself, so you will need to use a “proxy” A proxy is an outside app/code that will get the player’s avatar items and then you will request it from roblox studio.
These are my avatar items and you can view every detail about it (name, assetid, etc)
Summary: You’ll need to use outside code to get the player avatar items and then request it from studio, then update the rig’s avatar items. This requires effort and time and is suggested to be done with a person who knows at least 2 coding languages and is good with APIs.
(I recommend using python at replit, fastest and easiest proxy to make)
I’m pretty sure you can get better at these topics, APIs are really easy and interesting to use. Try to learn them if possible. No one started good at it but if you get deeper into the topic you’ll understand it eventually.
oh lol that’s true, I should’ve looked a bit on the documentations.
I mean you can look at this doc
game.Players:CreateHumanoidModelFromDescription(game.Players:GetHumanoidDescriptionFromUserId(1), Enum.HumanoidRigType.R15).Parent = game.Workspace looks like this work
> local Player = game.Players.LocalPlayer
> local Players = game:GetService("Players")
>
> local function iterPageItems(pages)
> return coroutine.wrap(function()
> local pagenum = 1
> while true do
> for _, item in ipairs(pages:GetCurrentPage()) do
> coroutine.yield(item, pagenum)
> end
> if pages.IsFinished then
> break
> end
> pages:AdvanceToNextPageAsync()
> pagenum = pagenum + 1
> end
> end)
> end
>
> local friendPages = Players:GetFriendsAsync(Player.UserId)
>
> local usernames = {}
>
> for item, _pageNo in iterPageItems(friendPages) do
> table.insert(usernames, item.Username)
> game.Players:CreateHumanoidModelFromDescription(game.Players:GetHumanoidDescriptionFromUserId(u
sernames), Enum.HumanoidRigType.R15).Parent = game.Workspace
end
How can i make it so it loads a certain amount of friends avatars? And how do i load the friends avatar?
You can get the friends from GetFriendsAsync, which returns a pages. Within that, you can loop through all of the pages and append their user IDs to a table.
Then, you can pick a few from that table and load their humanoid description onto a blank NPC.
You would pick them from the list you’ve created earlier.
local list = {} --the friends list
local objects = {} --output
local randoms = {}
local count = 5
for i = 1, count do
table.insert(randoms, math.random(1, #list))
end
for i = 1, #list do
if table.find(randoms, i) then
table.insert(objects, list[i])
end
end
print(objects)
> local friendPages = Players:GetFriendsAsync(Player.UserId)
>
> local usernames = {}
>
> for item, _pageNo in iterPageItems(friendPages) do
> table.insert(usernames, item.Username)
> game.Players:CreateHumanoidModelFromDescription(game.Players:GetHumanoidDescriptionFromUserId(u
local Player = game.Players.LocalPlayer
local Players = game:GetService("Players")
local function iterPageItems(pages)
return coroutine.wrap(function()
local pagenum = 1
while true do
for _, item in ipairs(pages:GetCurrentPage()) do
coroutine.yield(item, pagenum)
end
if pages.IsFinished then
break
end
pages:AdvanceToNextPageAsync()
pagenum = pagenum + 1
end
end)
end
local friendPages = Players:GetFriendsAsync(Player.UserId)
local usernames = {}
local objects = {} --output
local randoms = {}
local count = 5
for i = 1, count do
table.insert(randoms, math.random(1, #usernames))
end
for i = 1, #usernames do
if table.find(randoms, i) then
table.insert(objects, usernames[i])
end
end
print(objects)