How do I check friendship status on the client?

I have been restoring the 2014 CoreGUI, and one problem I have is checking if a player is friends with another via a localscript. Is this possible?

--[[
	gets enum val of friend status, uses pcall for some reason?(from old playerlist)
	@Args:
	player	player object to check if friends with
	@Return: enum of friend status
--]]
local function GetFriendStatus(player)
	if player == game.Players.LocalPlayer then
		return Enum.FriendStatus.NotFriend
	else
		local success, result = pcall(function() return game.Players.LocalPlayer:GetFriendStatus(player) end)
		if success then
			return result
		else
			return Enum.FriendStatus.NotFriend
		end
	end
end
1 Like

Have you tried using :IsFriendsWith()? It should simplify the script and get rid of the pcall() function.

if game.Players.LocalPlayer:IsFriendsWith(player.UserId) then
-- do stuff
else
-- do something else
end

I also need to tell if the user has sent a friend request, assuming it has not been accepted yet.

local function getFriendStatusIcon(friendStatus)
	if friendStatus == Enum.FriendStatus.Unknown or friendStatus == Enum.FriendStatus.NotFriend then
		return ""
	elseif friendStatus == Enum.FriendStatus.Friend then
		return "http://www.roblox.com/asset/?id=99749771"
	elseif friendStatus == Enum.FriendStatus.FriendRequestSent then
		return "http://www.roblox.com/asset/?id=99776888"
	elseif friendStatus == Enum.FriendStatus.FriendRequestReceived then
		return "http://www.roblox.com/asset/?id=99776838"
	else
		error("Unknown FriendStatus: " .. friendStatus)
	end
end

I’m not really familiar with friend requests in scripts, but how is the local function used in the script?

use IsFriendWith if they are already friends

also use the PlayerFriendedEvent and PlayerUnfriendedEvent for in game request and unfriends