Buy Currency, unable to cast array to int64

Hello, so I’ve been trying to make a cash shop through a ui. Seeing how I’m not the best scripter I followed a tutorial and looked around a bit. But when I finished the scripts I came with the error “Unable to cast Array to int64”. I was looking around the devforums for a solution but can’t seem to find one.

(I get the error with the script inside of the UI at line 25.)

ServerScriptService script

local mps = game:GetService("MarketplaceService")

local cashProductIds =
	{
		[1193666609] = 500,
		[1193666659] = 1000,
		[1193666716] = 2500,
		[1193666820] = 5000,
		[1193666898] = 10000,
		[1193667011] = 20000
	}

mps.ProcessReceipt = function(purchaseInfo)
	
	local plrPurchased = game.Players:GetPlayerByUserId(purchaseInfo.PlayerId)
	
	if not plrPurchased then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	for productID, cashGiven in pairs(cashProductIds) do
		if purchaseInfo.ProductId == productID then
			plrPurchased.HiddenData.Cash.Value = plrPurchased.HiddenData.Cash.Value + cashGiven
			return Enum.ProductPurchaseDecision.PurchaseGranted
		end
	end
	
end

Script in the ui

local mps = game:GetService("MarketplaceService")
local plr = game.Players.LocalPlayer

local cashProductIDs = 
	{
		1193666609,
		1193666659,
		1193666716,
		1193666820,
		1193666898,
		1193667011,
	}

local purchase500CashBtn = script.Parent.Button500
local purchase1000CashBtn = script.Parent["Button1.000"]
local purchase2500CashBtn = script.Parent["Button2.500"]
local purchase5000CashBtn = script.Parent["Button5.000"]
local purchase10000CashBtn = script.Parent["Button10.000"]
local purchase20000CashBtn = script.Parent["Button20.000"]

local function purchaseCashFunction(key)
	local idToPurchase = cashProductIDs
	mps:PromptProductPurchase(plr, idToPurchase)
end

purchase500CashBtn.MouseButton1Click:Connect(function()
	purchaseCashFunction(1)
end)

purchase1000CashBtn.MouseButton1Click:Connect(function()
	purchaseCashFunction(2)
end)

purchase2500CashBtn.MouseButton1Click:Connect(function()
	purchaseCashFunction(3)
end)

purchase5000CashBtn.MouseButton1Click:Connect(function()
	purchaseCashFunction(4)
end)

purchase10000CashBtn.MouseButton1Click:Connect(function()
	purchaseCashFunction(5)
end)

purchase20000CashBtn.MouseButton1Click:Connect(function()
	purchaseCashFunction(6)
end)

“Unable to cast Array to int64” is a error that you can fix doing:

local function purchaseCashFunction(key)
	local idToPurchase = cashProductIDs[key]
	mps:PromptProductPurchase(plr, idToPurchase)
end

It should fix, try testing that.

It is because the argument isn’t type of int64, it’s an array:

local idToPurchase = cashProductIDs
mps:PromptProductPurchase(plr, idToPurchase)

“idToPurchase” is an array, thats why you getting error

Omg, thank you. I just realised like u said I completely forgot to show the argument its an array.
It works now.

Once again thank you for your help.

No problem, keep doing stuff :slight_smile: