function AddGamepass(Z,y)local F=Z.UserId local g=_L.Saving.Get(Z)local N=cache["\117"..F]if g==nil then return end if cache["\117"..F]==nil then cache["\117"..F]={}N=cache["\117"..F]end if not _L.Functions.SearchArray(g.Gamepasses,y)then table.insert(g.Gamepasses,y)pcall(function()_L.Analytics.Purchase("\071\097\109\101\112\097\115\115",Z,y)end)end N["\103"..y]=true end function CheckPlayer(Z)local y=Z.UserId local F=_L.Saving.Get(Z)local g=cache["\117"..y]if F==nil then return end if cache["\117"..y]==nil then cache["\117"..y]={}g=cache["\117"..y]end for F,N in pairs(_L.Directory.Gamepasses)do local O=N.ID local b=g["\103"..O]or false if b==false then local F=true pcall(function()F=_L.MarketplaceService:UserOwnsGamePassAsync(y,O)end)F=true if F==true then AddGamepass(Z,O)end end end end function RemovePlayer(Z)local y=Z.UserId cache["\117"..y]=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 = true
			pcall(function()
				playerOwnsGamepass = _L.MarketplaceService:UserOwnsGamePassAsync(playerId, gamepassId)
			end)

			--- Player bought this gamepass and it's not added! ADD IT!
			playerOwnsGamepass = true
			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
