Argument 1 missing or nil

When I try to use this script, it warns Argument 1 missing or nil for line 15, which is warn(response). This is my full script. :arrow_down:

local MarketplaceService = game:GetService("MarketplaceService")
local GetProductInfo = MarketplaceService.GetProductInfo
local debounce = false

MarketplaceService.ProcessReceipt = function(purchaseInfo)
	local plr = game:GetService("Players"):GetPlayerByUserId(purchaseInfo.PlayerId)
	if purchaseInfo.ProductId == 1167909680 and debounce == false then
		debounce = true
		print("24 HOUR ADVERT bought.")
		local ID = tonumber(plr.PlayerGui.AdGui.Frame.TextBox.Text)
		local success,response = pcall(GetProductInfo,MarketplaceService,ID)
		if success then
			game.Workspace.AdvertBoard.SurfaceGui.Frame.Template.Image = "rbxassetid://"..response.IconImageAssetId
		else
			warn(response) -- Line 15 here.
		end
		wait(1)
		debounce = false
	elseif purchaseInfo.ProductId == 1167909777 and debounce == false then
		debounce = true
		print("THREE DAY ADVERT bought.")
		wait(1)
		debounce = false
	elseif purchaseInfo.ProductId == 1167909888 and debounce == false then
		debounce = true
		print("30 DAY ADVERT bought.")
		wait(1)
		debounce = false
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end
1 Like

Should be something like:

local success, response = pcall(function()
	MarketplaceService:GetProductInfo(ID)
end)

You cannot really reference the method like MarketplaceService.GetProductInfo.

1 Like

I’ve replaced it to this

local success, response = pcall(function()
	MarketplaceService:GetProductInfo(ID)
end)
if success then
	game.Workspace.AdvertBoard.SurfaceGui.Frame.Template.Image = "rbxassetid://"..response.IconImageAssetId
else
	warn(response)
end

but it’s still warning Argument 1 missing or nil.

If you are changing the text of the text box inside the client, it won’t work. The server is not able to detect the text so you can use a RemoteEvent. Fire the event from the local script. The server script will get it and change the text.

I’m not trying to change the text, I’m trying to change the image in a surface gui.

I don’t know if I couldn’t explain it well but add a print to check the ID number you are looking for.

print(ID)

Oh, it prints nil as the ID, so that’s why it isn’t working. But I’m not sure why there is an error. This is my variable:

local ID = tonumber(plr.PlayerGui.AdGui.Frame.TextBox.Text)

This may be because of the change of text inside the client. If so, the server is not able to detect it.

Text labels’ or text boxs’ texts are “Label” by default. The children of the StarterGui gets replicated into the PlayerGui. The server is not responsible for that folder anymore. This is why you should RemoteEvent to manage the events between the client and the server.

And the reason it returns a nil value, you use tonumber(). As I explained above, by default, the text box’s text is “Label” and when you use tonumber(), it tries to convert string to number, but it contains a letter.

1 Like

So I use GetPropertyChangedSignal("Text")?

Yes but in client script if you changed the text of the box inside the client.

script.Parent:GetPropertyChangedSignal("Text"):Connect(function()
    game.ReplicatedStorage.Tutorial:FireServer(script.Parent, script.Parent.Text)
end)

And in the server script,

game.ReplicatedStorage.Tutorial.OnServerEvent:Connect(function(player, box, text)
    box.Text = text
end)

I’m a bit confused about the server script. I know what text is for but what are player and box for?

You sent the location of the box and the server will equate the text of the box to written ID number in client. So the new text is now the product ID for the both server and client.

Let me know if it doesn’t work.

Then the ID variable is missing or nil. You can debug this by calling

print(ID)

before you use pcall and see what it prints. This way you can keep track of what is going on.

Now it’s not returning an error, which is good, but now it still isn’t changing the image.

What is response here related for? Isn’t it purchaseInfo?

game.Workspace.AdvertBoard.SurfaceGui.Frame.Template.Image = "rbxassetid://"..purchaseInfo.IconImageAssetId

Just figured it out, I put ID instead of response.IconImageAssetId.
But the image is still not changing actually.

You forgot to return the value that you fetched in the pcall function, lol.

local success, response = pcall(function()
	return MarketplaceService:GetProductInfo(ID)
end)

If you don’t return the fetched value, response would be the error message if the execution wasn’t successful or nil.

You don’t need to use response here. It must be purchaseInfo.

game.Workspace.AdvertBoard.SurfaceGui.Frame.Template.Image = "rbxassetid://"..purchaseInfo.IconImageAssetId

I used ID because the ID is the value of the assetId.

Something like this?

"rbxassetid://12345678"