Argument 2 missing or nil

Hello

So i followed a tutorial “How to make a Donation Board” and for some reason it doesn’t work. Whenever i’ll try to donate something or just clicka button nothing will happen and error pops up in output.

Output:

Argument 2 missing or nil - Server - Script:21
Stack Begin - Studio
Script ‘Workspace.DonationBoard.Main.SurfaceGui.Script’, Line 21 - Studio - Script:21
Stack End - Studio

Script:

local donateAmounts = {10, 25, 50, 100, 250, 500, 1000}
local ids = {1379354079, 1379354269, 1379354329, 1379354399, 1379354467, 1379354535, 1379354610}
local mps = game:GetService("MarketplaceService")
local dss = game:GetService("DataStoreService")
local ods = dss:GetOrderedDataStore("Donators")

for i, amount in pairs(donateAmounts) do

local donateButton = script:WaitForChild("DonateButton"):Clone()
donateButton.Amount.Text = amount .. " R$"
donateButton.Parent = script.Parent.Parent.Parent.Buttons.SurfaceGui.Frame.ScrollingFrame

end

game.ReplicatedStorage.Remotes.Donate.OnServerEvent:Connect(function(plr, button)

local amount = string.gsub(button.Amount.Text, " R$", "")
local id = ids[table.find(donateAmounts, tonumber(amount))]

mps:PromptProductPurchase(plr, id) -- Argument 2 missing or nil (line 21)

end)

The error is Appearing after click Donate Button

Uh, can you explain what you are trying to accomplish here:

game.ReplicatedStorage.Remotes.Donate.OnServerEvent:Connect(function(plr, button)

local amount = string.gsub(button.Amount.Text, " R$", "")
local id = ids[table.find(donateAmounts, tonumber(amount))]

mps:PromptProductPurchase(plr, id) -- Argument 2 missing or nil (line 21)

end)

Have you tried using a Positive Integer Mask instead of
local amount = string.gsub(button.Amount.Text, " R$", "")

Positive Integer Mask:

function PositiveIntegerMask(text)
	return text:gsub("%D+", "")
end

Something like this:

local amount = PositiveIntegerMask(button.Amount.Text)
local id = ids[table.find(donateAmounts, tonumber(amount))]

uhh what is the tutorial link if you are following the tutorial

I made my own donation board but changed everything to work

1 Like

I tried using that but it returns the same error

1 Like

well, there is the model and the scripts in the description though…

also, did you turn on Allow Third Party Sales?

1 Like

Yes, I know there are scripts in the description and I copied them and still they don’t work.

Yes I did turn that on

1 Like

I tried testing it using this:

local donateAmounts = {10, 25, 50, 100, 250, 500, 1000}
local ids = {1379354079, 1379354269, 1379354329, 1379354399, 1379354467, 1379354535, 1379354610}

function PositiveIntegerMask(text)
	return text:gsub("%D+", "")
end

local amount = PositiveIntegerMask("25 R$")
print(amount)
local id = ids[table.find(donateAmounts, tonumber(amount))]
print(id)

image
It seems to be working for me

2 Likes

It works!

I think I misspelled something before that’s why it didn’t work for the first time.
Thank you so much

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.