Help with developer products

Hello, I got this code from Roblox’s code sample, but this code doesn’t seem to work. I have the script inside the TextButton. The error prints out the player should be a type of a player, but is a type of a nill.
Is there a way to fix this? Thank you.

This is the script that I got from Roblox’s code sample. Also, I added script.Parent.MouseButton1Click:Connect(promptPurchase).

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
 
local productID = -- My developer product id
 
-- Function to prompt purchase of the developer product
local function promptPurchase()
	local player = Players.LocalPlayer
	MarketplaceService:PromptProductPurchase(player, productID)
end

script.Parent.MouseButton1Click:Connect(promptPurchase)

Also, I have a question, if I don’t script for the receipt, will I not get the Robux that player bought?

1 Like

You will get the robux, just the player won’t get anything.

1 Like

I don’t see why this wouldn’t work…
How exactly isn’t it working again?

Edit: Nevermind

1 Like

Is it a local or server script? If it’s a server script, then LocalPlayer would be nil.

1 Like

It’s a Script, and it’s located under the TextButton.

1 Like

That’s the problem. It should be a LocalScript.

2 Likes

Ok, let me try it out and tell you.

1 Like

Now, when I switched it to a LocalScript, the error doesn’t pop up anymore, but the developer product gui doesn’t pop up.

1 Like

Even when you click it a couple of times? It could be a debounce glitch.

1 Like

Yes, I clicked 3 times, but it still doesn’t show.

1 Like

Well then, I don’t really know.

1 Like

Ok, but thanks for trying to help me. :grinning:

1 Like

yes, but the clicking thing only works in localscripts

Yeah, i looked at the example page, tried to delete my post. Guess it has to be local.

1 Like

To prompt a purchase it must be a server script but to check when the button is locked you must use a local script if the button is on GUI.
So you will then need to use a remote event to connect the local script to the server script.

1 Like

The developer.roblox.com example implies that you use a localscript:
image

See there example uses Players.LocalPlayer

Oh, it sound really complicated. Is there a way to just prompt a purchase with a script?

Also, @Sir_Highness, the image you replied to seancool07777 is the page that I followed.

Here is a similar example I found on devforum:

1 Like

Thanks, I will have to try that later.

Would it be possible to see you’re layout for the GUI, you’re code theoretically works, therefore I feel like its nothing to do with the script.

2 Likes