local function P(P,T)local D,c=getAsset(T)if D then local T=Datastore:GetData(P)if D.onPurchased then D.onPurchased(P)end if c=="\080\097\115\115\101\115"and T then local P=T.Gamepasses or{}table.insert(P,D.Id)T.Gamepasses=P end end end MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(T,D,c)if c and T.Parent then P(T,D)game.ReplicatedStorage.RE.gamepassUpdate:FireClient(T,getNameFromID(D))end end)MarketplaceService.PromptProductPurchaseFinished:Connect(function(T,D,c)local N=game.Players:GetPlayerByUserId(T)if c and(N and N.Parent)then P(N,D)end end)

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)


