Hello I have an Script that shows Online and Offline friends and even possibly the games they are playing in the future but theres an bug where everyone just shows offline even though they are online or playing an game here is the script provided
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local player = Players.LocalPlayer
local list = script.Parent.List
-- clear old entries
for _, child in pairs(list:GetChildren()) do
if child:IsA("Frame") then
child:Destroy()
end
end
-- layout
local layout = Instance.new("UIListLayout")
layout.Padding = UDim.new(0, 8)
layout.Parent = list
-- Step 1: all friends
local allFriends = {}
local success, pages = pcall(function()
return Players:GetFriendsAsync(player.UserId)
end)
if success then
repeat
for _, friend in ipairs(pages:GetCurrentPage()) do
allFriends[friend.Id] = {
displayName = friend.DisplayName,
username = friend.Username,
online = false,
lastLocation = nil,
placeId = nil
}
end
until pages.IsFinished or not pages:AdvanceToNextPageAsync()
else
warn("Failed to get all friends")
return
end
-- Step 2: online friends
local successOnline, onlineFriends = pcall(function()
return player:GetFriendsOnlineAsync()
end)
if successOnline then
for _, friend in ipairs(onlineFriends) do
if allFriends[friend.UserId] then
allFriends[friend.UserId].online = true
allFriends[friend.UserId].lastLocation = friend.LastLocation
allFriends[friend.UserId].placeId = friend.PlaceId
end
end
else
warn("Failed to get online friends")
end
-- Step 3: build UI
for _, data in pairs(allFriends) do
local frame = Instance.new("Frame")
frame.Size = UDim2.new(1, -10, 0, 60)
frame.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
frame.BorderSizePixel = 0
frame.Parent = list
-- Name label
local nameLabel = Instance.new("TextLabel")
nameLabel.Size = UDim2.new(1, -12, 0, 28)
nameLabel.Position = UDim2.new(0, 6, 0, 4)
nameLabel.BackgroundTransparency = 1
nameLabel.TextXAlignment = Enum.TextXAlignment.Left
nameLabel.Font = Enum.Font.GothamBold
nameLabel.TextSize = 16
nameLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
if data.displayName and data.displayName ~= data.username then
nameLabel.Text = string.format("%s (@%s)", data.displayName, data.username)
else
nameLabel.Text = "@" .. data.username
end
nameLabel.Parent = frame
-- Status label
local statusLabel = Instance.new("TextLabel")
statusLabel.Size = UDim2.new(1, -12, 0, 20)
statusLabel.Position = UDim2.new(0, 6, 0, 32)
statusLabel.BackgroundTransparency = 1
statusLabel.TextXAlignment = Enum.TextXAlignment.Left
statusLabel.Font = Enum.Font.Gotham
statusLabel.TextSize = 14
statusLabel.Parent = frame
if data.online then
if data.placeId and data.placeId ~= 0 then
statusLabel.Text = "Playing a game"
statusLabel.TextColor3 = Color3.fromRGB(0, 170, 255)
else
statusLabel.Text = "Online"
statusLabel.TextColor3 = Color3.fromRGB(0, 255, 0)
end
else
statusLabel.Text = "Offline"
statusLabel.TextColor3 = Color3.fromRGB(160, 160, 160)
end
end
