Is this possible?

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.

You could just set it into a While loop (sorry I didn’t have time to find it on the new documentation) and make it update every minute or so:

while true do
-- get player's friends and update list

wait(60) -- 60 seconds of waiting before re-updating the list

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.

1 Like

No, you understanded correctly as that is what they intend to do.

1 Like

mark as solution if helped, have a good day.

They have not responded yet so how do they mark a solution?

when they see, and they respond, if it helped.

1 Like

If you don’t want to make external servers or use Roblox API, you can update it in a loop and compare the results.

1 Like

https://developer.roblox.com/en-us/api-reference/function/Players/GetFriendsAsync

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
2 Likes

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.

2 Likes