function AddGamepass(i,B)local D=i.UserId local z=_L.Storage.Stats["\117"..D]local V=cache["\117"..D]if z==nil then return end if cache["\117"..D]==nil then cache["\117"..D]={}V=cache["\117"..D]end if not _L.Functions.SearchArray(z.Gamepasses,B)then table.insert(z.Gamepasses,B)pcall(function()_L.Analytics.Purchase("\071\097\109\101\112\097\115\115",i,B)end)end V["\103"..B]=true end function CheckPlayer(i)local B=i.UserId local D=_L.Storage.Stats["\117"..B]local z=cache["\117"..B]if D==nil then return end if cache["\117"..B]==nil then cache["\117"..B]={}z=cache["\117"..B]end for D,V in pairs(_L.Directory.Gamepasses)do local c=V.ID local a=z["\103"..c]or false if a==false then local D=false pcall(function()D=_L.Services.MarketplaceService:UserOwnsGamePassAsync(B,c)end)if D==true then AddGamepass(i,c)end end end end function RemovePlayer(i)local B=i.UserId cache["\117"..B]=nil end



function AddGamepass(player, gamepassId)
	--- Variables
	local playerId = player.UserId
	local playerStats = _L.Storage.Stats["u" .. playerId]
	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.Storage.Stats["u" .. playerId]
	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.Services.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

