GetFriendsOnline is unreliable

This feature, the GetFriendsOnline method, has become kinda useless due to the way it prioritises activity from friends. Any website activity will set a friend’s LocationType to 2 (AKA website) even if they are in-game or studio, and both games and studio seem to only infrequently send updates about a user’s activity. This means that someone could be in team create for hours, for example, but if they use the website once they will display as being on the website (and not in team create) for that length of time when this method is called.

This behaviour runs differently to how developers would actually want to use this feature. One example is making a ‘join a friend’ system in a multi-place game. If you tried to use the GetFriendsOnline method in this scenario, you will find that often the information is inaccurate (e.g. saying a friend is on the website when in fact they are playing the game) and therefore the system doesn’t work.

This might be why I haven’t seen many games actually using this feature or features like it and when I have, they are usually doing a manual username input (‘type in the name of the player you would like to join’) combined with GetPlayerPlaceInstanceAsync since it is more reliable.

So please implement some changes at least to the way activities are prioritised so that this feature becomes usable :slight_smile:

15 Likes

Hello,

I was looking for a way to make a GUI displaying which of your friends are online in our game. My initial experiment with player:GetFriendsOnline seemed a success, until I found an issue that completely prevents it’s application for this use case.

The script will output “<friendname> has come online!” and “<friendname> has gone offline!” whenever a friend joins or leaves one of the places whose ID is in the ourPlaceIds table.

This works really well, and within 15 seconds after my friend joining or leaving my place, the respective message would come up correctly.

However, when my friend would stay in game but start browsing the website, suddenly my script would output “<friendname> has gone offline!”

When I print the LocationType in that case, it shows “2” which indicates the website.

I have attached a place file below with the code displayed at the bottom of this post installed. Add your places placeId to the table, press ‘play’ and ask your friend to join the place with that placeId / leave / stay in the background but browse the roblox website.

I am aware of Players:GetFriendsAsync(), however it does not provide me with the right information (place ID). An inactivated script to demonstrate this can also be found in this place file under ServerScriptService. Other ideas to achieve my use case are also very welcome, or I will resort to messagingService (I would prefer to not spend it’s usage quota on this). The most ideal solution would be a player.FriendStatusChanged type of event that we could connect to, in my opinion.

getfriendsonline.rbxl (20.2 KB)

The Script

local ourPlaceIds = {"123456789", "4815150781"} -- Enter your place IDs here.

local function isInOurGame(placeId)
	
	for i, ourPlaceId in pairs(ourPlaceIds) do
		if ourPlaceId == tostring(placeId) then
			return true
		end
	end
	
	return false
	
end

local onlineFriends = {}

local function cameOnline(friendName)
	print(friendName .. " is online!")
end

local function wentOffline(friendName)
	print(friendName .. " went offline!")
end

local function getFriendsOnline()
	
	local success, returnData = pcall( function()
		return game.Players.LocalPlayer:GetFriendsOnline()
	end)
	
	if not success then
		warn("Warning! Cannot retrieve friends list. Error: ", returnData)
		return
	end
		
	local friendsOnline = returnData

	for j, friendData in pairs(friendsOnline) do
		
		local friendId = tostring(friendData["VisitorId"])
		local friendName =friendData["UserName"] 
		
		local inOurGame = isInOurGame(friendData["PlaceId"])
		
		if( friendData["IsOnline"] ) and inOurGame then
			
			if not onlineFriends[friendId] then
				cameOnline(friendName)
				onlineFriends[friendId] = true
			end
		else
			if onlineFriends[friendId] then
				
				print("GameId : ", friendData["GameId"])
				print("LastOnline : ", friendData["LastOnline"])
				print("IsOnline : ", friendData["IsOnline"])
				print("PlaceId : ", friendData["PlaceId"])
				print("LocationType : ", friendData["LocationType"])
				print(friendName)
				
				
				wentOffline(friendName)
				onlineFriends[friendId] = nil
			end
		end
	
--		for i, v in pairs(friendData) do
--			print (i, v)
--		end
			
	end
end

wait(1)
while true do
	
	getFriendsOnline()
	wait(15)
end		

4 Likes