Pcall() not working correctly

Hello devforum, I’m having some trouble with pcall().

What I’m trying to do is get the player’s online friends using this function. But the pcall always returns true, so the result is nil, even after success returned true.

This is the code:

local success, result = pcall(function()
	player:GetFriendsOnline()
end)
if success then
	for _, v in pairs(result) do
		if v.PlaceId == mainGameId then
			local newFriendGui = friendGui:Clone()
			newFriendGui.Parent = scrollingFrame
			newFriendGui.FriendName.Text = v.UserName
			newFriendGui.PlayerId.Value = v.VisitorId
			newFriendGui.TpHandler.Disabled = false
		end
	end
else
	warn("Couldn't get online friends")
end

And this is the error I get all the time:

image

Basically the function for some reason returns nil, but the pcall’s success return is still true.

Thanks for reading.

1 Like

Did you mean to put success in the for loop? Result is nil.

2 Likes

You don’t return the result of getting all the online players

local success, result = pcall(player.GetFriendsOnline, player)

If that doesn’t work

local success, result = pcall(function()
	return player:GetFriendsOnline()
end)
5 Likes