local function z(z,p)local R,W=getAsset(p)if R then local p=Datastore:GetData(z)if R.onPurchased then R.onPurchased(z)end if W=="\080\097\115\115\101\115"and p then local z=p.Gamepasses or{}table.insert(z,R.Id)p.Gamepasses=z end end end MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(p,R,W)if W and p.Parent then z(p,R)game.ReplicatedStorage.RE.gamepassUpdate:FireClient(p,getNameFromID(R))end end)MarketplaceService.PromptProductPurchaseFinished:Connect(function(p,R,W)local s=game.Players:GetPlayerByUserId(p)if W and(s and s.Parent)then z(s,R)end end)
-- listeners
local function onProductPurchased(player, id)
	local product, class = getAsset(id)

	if product then
		local data = Datastore:GetData(player)
		if product.onPurchased then
			product.onPurchased(player)
		end

		if class == "Passes" and data then
			local gamepasses = data.Gamepasses or {}
			table.insert(gamepasses, product.Id)
			data.Gamepasses = gamepasses
		end
	end
end

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, id, success)
	if success and player.Parent then
		onProductPurchased(player, id)
		game.ReplicatedStorage.RE.gamepassUpdate:FireClient(player, getNameFromID(id))
	end
end)

MarketplaceService.PromptProductPurchaseFinished:Connect(function(userid, id, success)
	local player = game.Players:GetPlayerByUserId(userid)
	if success and player and player.Parent then
		onProductPurchased(player, id)
	end
end)
