local Q={}function CheckFriendship(T,S)if T==nil or S==nil or Q[T.Name]==nil or Q[S.Name]==nil then return false end local w=false local t=false for Q,T in pairs(Q[T.Name])do if T==S.userId then w=true break end end for Q,S in pairs(Q[S.Name])do if S==T.userId then t=true break end end if w==true and t==true then return true else return false end end game.ReplicatedStorage.RemoteFunctions.SendFriendsOnlineData.OnServerEvent:connect(function(T,S)if type(S)=="\116\097\098\108\101"and#S<=200 then for Q,T in pairs(S)do if type(T)~="\110\117\109\098\101\114"then return end end Q[T.Name]=S end end)game.ServerStorage.RemoteFunctions.PlayersAreFriends.OnInvoke=function(Q,T)return CheckFriendship(Q,T)end game.Players.PlayerRemoving:connect(function(T)Q[T.Name]=nil end)
--when verifying friendships, we just check both the caller and the target's friend lists to see if the IDs are found in both lists

local friendlists = {} --Key: person's username. Value: table of online friends' user IDs

function CheckFriendship(caller, target)
	if caller == nil or target == nil or friendlists[caller.Name] == nil or friendlists[target.Name] == nil then
		return false
	end
	local f1 = false
	local f2 = false
	for _, v in pairs(friendlists[caller.Name]) do
		if v == target.userId then
			f1 = true
			break
		end
	end
	for _, v in pairs(friendlists[target.Name]) do
		if v == caller.userId then
			f2 = true
			break
		end
	end
	if f1 == true and f2 == true then
		return true
	else
		return false
	end
end

game.ReplicatedStorage.RemoteFunctions.SendFriendsOnlineData.OnServerEvent:connect(
	function(plr, tbl) --client should send a table of all friend userIDs
		if type(tbl) == "table" and #tbl <= 200 then
			for _, v in pairs(tbl) do
				if type(v) ~= "number" then
					return
				end
			end
			friendlists[plr.Name] = tbl
		end
	end
)

game.ServerStorage.RemoteFunctions.PlayersAreFriends.OnInvoke = function(caller, target)
	return CheckFriendship(caller, target)
end

game.Players.PlayerRemoving:connect(function(plr)
	friendlists[plr.Name] = nil
end)
