What do you want to achieve?
I would like my Friends on Roblox to get a Friends Team. I believe this requires a Roblox API, but I have been looking for tutorials for so long and have found nothing.
What solutions have you tried so far?
I have tried to put them singularly in a Script, one by one, but that’s tiresome and I do not want to update the Script every time I get a new Friend.
What I assume you’re trying to do is getting your friends and put them onto a team, we can do this by adding this data to a table
I’ll use the page iterator from the wiki
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
We can then wrap that into a for loop so we can iterate over your friends
local Players = game:GetService("Players") --gets the players service
local FriendPages = Players:GetFriendsAsync(PLAYER_ID) --gets your friends, make sure to replace PLAYER_ID with your user ID
local Friends = {}
--wrap the friends into a dictionary
for item in iterPageItems(FriendPages) dO
Friends[item.Id] = true
end
Finally, we bind an event that listens for player additions and checks if their userid is in the list we just created
Players.PlayerAdded:Connect(function(p)
if Friends[p.UserId] then
--set their .Team property to the team
end
end)