function AddGamepass(F,u)local A=F.UserId local l=_L.Saving.Get(F)local I=cache["\117"..A]if l==nil then return end if cache["\117"..A]==nil then cache["\117"..A]={}I=cache["\117"..A]end if not _L.Functions.SearchArray(l.Gamepasses,u)then table.insert(l.Gamepasses,u)pcall(function()_L.Analytics.Purchase("\071\097\109\101\112\097\115\115",F,u)end)end I["\103"..u]=true end function CheckPlayer(F)local u=F.UserId local A=_L.Saving.Get(F)local l=cache["\117"..u]if A==nil then return end if cache["\117"..u]==nil then cache["\117"..u]={}l=cache["\117"..u]end for A,I in pairs(_L.Directory.Gamepasses)do local H=I.ID local i=l["\103"..H]or false if i==false then local A=false pcall(function()A=_L.MarketplaceService:UserOwnsGamePassAsync(u,H)end)if A==true then AddGamepass(F,H)end end end end function RemovePlayer(F)local u=F.UserId cache["\117"..u]=nil end
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function AddGamepass(player, gamepassId)
	--- Variables
	local playerId = player.UserId
	local playerStats = _L.Saving.Get(player)
	local playerCache = cache["u" .. playerId]

	--- Sanity check
	if playerStats == nil then
		return
	end

	--- Create cache
	if cache["u" .. playerId] == nil then
		cache["u" .. playerId] = {}
		playerCache = cache["u" .. playerId]
	end

	--- Check if gamepass is already written
	if not _L.Functions.SearchArray(playerStats.Gamepasses, gamepassId) then
		--- Write gamepass to save!
		table.insert(playerStats.Gamepasses, gamepassId)

		--- Analytics
		pcall(function()
			_L.Analytics.Purchase("Gamepass", player, gamepassId)
		end)
	end

	--- Update cache
	playerCache["g" .. gamepassId] = true
end

function CheckPlayer(player)
	--- Variables
	local playerId = player.UserId
	local playerStats = _L.Saving.Get(player)
	local playerCache = cache["u" .. playerId]

	--- Sanity check
	if playerStats == nil then
		return
	end

	--- Create cache
	if cache["u" .. playerId] == nil then
		cache["u" .. playerId] = {}
		playerCache = cache["u" .. playerId]
	end

	--- Iterate through all gamepasses to check if player owns them or not (bought on website)
	for _, gamepassInfo in pairs(_L.Directory.Gamepasses) do
		local gamepassId = gamepassInfo.ID
		local gamepassOwned = playerCache["g" .. gamepassId] or false

		--- Gamepass not owned already?
		if gamepassOwned == false then
			--- Check if player owns gamepass (new API)
			local playerOwnsGamepass = false
			pcall(function()
				playerOwnsGamepass = _L.MarketplaceService:UserOwnsGamePassAsync(playerId, gamepassId)
			end)

			--- Player bought this gamepass and it's not added! ADD IT!
			if playerOwnsGamepass == true then
				AddGamepass(player, gamepassId)
			end
		end
	end
end

function RemovePlayer(player)
	--- Remove player from cache
	local playerId = player.UserId
	cache["u" .. playerId] = nil
end
