To make a friends list which updates anytime a friend goes online/offline?
I already know how to make a friends/offline friends list [GetFriendsAsync]
However, is it possible to detect when those friends go online/offline and update it in the game servers?
--//Variables/Services/Functions
local Players = game:GetService("Players")
local UserId = 370831180
local friendPages = Players:GetFriendsAsync(UserId)
local usernames = {}
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
--//Loops/Calls/Prints
for item, pageNo in iterPageItems(friendPages) do
table.insert(usernames, item.Username)
end
for _,friend in pairs(usernames) do
if not script.Parent.LIST:FindFirstChild(friend) then
local clone = script.Parent.LIST.Template:Clone()
clone.Name = friend
clone.Visible = true
clone.UserName.Text = friend
local id = Players:GetUserIdFromNameAsync(friend)
local suc1,res1 = pcall(function()
return Players:GetUserThumbnailAsync(id,Enum.ThumbnailType.HeadShot,Enum.ThumbnailSize.Size180x180)
end)
if suc1 then
clone.Image = res1
end
clone.Parent = script.Parent.LIST
end
end
print("Friends: " .. table.concat(usernames, ", "))
I have this simple script which creates a list of my friends and clones their images and names into a scrollinglist.
yes, you can do that with noblox.js, make a code with JavaScript using noblox.js in websites like repl.it, and make a post with HttpService to that, but this is very advanced.
GetFriendsAsync returns a ‘FriendPages’ object where each page’s items contain a ‘IsOnline’ Boolean property.
do
local Game = game
local Players = Game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Success, Result = pcall(Players.GetFriendsAsync, Players, LocalPlayer.UserId)
if not Success then warn(Result) return end
local Friends = {} --Cache of friends.
while true do
local Page = Result:GetCurrentPage()
for _, Item in ipairs(Page) do
table.insert(Friends, Item) --Item contains a 'IsOnline' Boolean field.
end
if Result.IsFinished then
break
else
Result:AdvanceToNextPageAsync()
end
end
while true do
task.wait(1) --This can be changed if you want to increase/decrease the amount of issued requests.
Success, Result = pcall(LocalPlayer.GetFriendsOnline, LocalPlayer)
if not Success then warn(Result) continue end
for _, Friend in ipairs(Friends) do
local State = false
for _, Item in ipairs(Result) do
if Friend.Id == Item.VisitorId then State = true break end
end
Friend.IsOnline = State
for Field, Value in pairs(Friend) do
print(Field, Value)
end
end
end
end
Yeah, but is there a way to detect in-game if they changed that property ? so that if there is a friends list, and player X goes from online to offline, it shows it in the list [say, change status text to ‘offline’]
There aren’t events that detect this but you can repetitively query GetFriendsOnline or GetFriendsAsync like in the above example to determine when friends are online/offline.