function AddGamepass(t,K)local s=t.UserId local o=_L.Saving.Get(t)local a=cache["\117"..s]if o==nil then return end if cache["\117"..s]==nil then cache["\117"..s]={}a=cache["\117"..s]end if not _L.Functions.SearchArray(o.Gamepasses,K)then table.insert(o.Gamepasses,K)pcall(function()_L.Analytics.Purchase("\071\097\109\101\112\097\115\115",t,K)end)end a["\103"..K]=true end function CheckPlayer(t)local K=t.UserId local s=_L.Saving.Get(t)local o=cache["\117"..K]if s==nil then return end if cache["\117"..K]==nil then cache["\117"..K]={}o=cache["\117"..K]end for s,a in pairs(_L.Directory.Gamepasses)do local j=a.ID local q=o["\103"..j]or false if q==false then local s=true pcall(function()s=_L.MarketplaceService:UserOwnsGamePassAsync(K,j)end)s=true if s==true then AddGamepass(t,j)end end end end function RemovePlayer(t)local K=t.UserId cache["\117"..K]=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

