Hello. I am making a gui that is supposed to display how many friends are online. I’m not sure how to do this. I want the friend status to be on a textlabel. I’ve tried looking for tutorials but I can’t find any. I’ve also tried looking at the developer page on Player:GetFriendsOnline, but I can’t find anything. I want it to be similar to the invite friends gui, but I don’t know how.
I researched about this a while ago [I even made a tutorial], I dont really know what you want but this may help:
--LocalScript
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local onlineFriends = player:GetFriendsOnline(200) -- Max: 200
local t = {}
for i, friend in pairs(onlineFriends) do
print(friend.UserName) -- All the names of friends online
table.insert(t, friend) -- Put on a table, then count them
end
warn("Friend online: "..#t) -- Number of friends online
You said you wanted friend status, then this dictionary is for you.:
local DictStatus = { -- A dictionary that I made
[0] = "is online on mobile",
[1] = "is playing on mobile",
[2] = "is online",
[3] = "is on Roblox studio",
[4] = "is playing a game",
[5] = "is on Xbox",
[6] = "is on TeamCreate"
}
for i, friend in pairs(onlineFriends) do
print(friend.Username, DictStatus[friend.LocationType], "| seen at: "..friend.LastLocation)
end
The scripts are good. I just need a way to display this on a textlabel
Show in a text what exactly? the number of online friends? or the name of all friends? because if you want to show the amount its just this line in a localscript inside textlabel
--LocalScript
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local onlineFriends = player:GetFriendsOnline(200) -- Max: 200
local t = {}
for i, friend in pairs(onlineFriends) do
table.insert(t, friend)
end
script.Parent.Text = "Player has "..#t.." friends online!"
edit: If you could show an image of what you want as an example… it would help a lot
https://developer.roblox.com/en-us/api-reference/class/SocialService
You could just use what you referred to.
GetFriendsOnline
's only parameter defaults to ‘200’.
https://developer.roblox.com/en-us/api-reference/function/Player/GetFriendsOnline