PromptPurchase not working

Basically I’m making a donation board for my game and I’ve made it so that when one of the interactable buttons are clicked the game prompt’s a dev product. But it’s not doing that, infact it seems that the game is not recognizing the player clicking the button at all. I’m getting no error messages, Does anyone know why?

Edit: I’ve spent way to long trying to get a physical leaderboard working so I’m going to make a ui based one instead.

1 Like

Does it ever print “Donate”? If so at least we know the event is firing on the client but likely not being send/received by the server, if not then you may have an issue with click detection on the part(s) your clicking on preventing the event from even firing locally. Your code “looks like it should run” but something is a miss and chances are it’s related to the event.

From the examples in the documentation for the MarketplaceService, you may need to use both a client and server script if you want to connect it to an event vs just firing it by calling on the function directly.

Pulled from the documentation.

--Client Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local promptPurchaseEvent = ReplicatedStorage:WaitForChild("PromptPurchaseEvent")

local part = Instance.new("Part") --adjust or remove
part.Parent = workspace

local clickDetector = Instance.new("ClickDetector") --adjust or remove
clickDetector.Parent = part

clickDetector.MouseClick:Connect(function() --adjust to miniDonation.MouseButton2Click...
	promptPurchaseEvent:FireServer(16630147) --change to ProductId, you only need to specify the product, Player should be handed off to the server with the event, all on it's own.
end)
--Server script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")

local promptPurchaseEvent = Instance.new("RemoteEvent")
promptPurchaseEvent.Name = "PromptPurchaseEvent"
promptPurchaseEvent.Parent = ReplicatedStorage

-- Listen for the RemoteEvent to fire from a Client and then trigger the purchase prompt
promptPurchaseEvent.OnServerEvent:Connect(function(player, id)
	MarketplaceService:PromptPurchase(player, id)
end)

Hope that helps.

2 Likes

Are you testing the button with a left click? You have the function connected to MouseButton2Click which is a right click.

2 Likes

What’s not working is that the game is not processing whenever a click the gui I have done some looking around to see what the problem is. Btw I’m using a surface gui with a frame and inside that fram is a textbutton which is where the script is located.

2 Likes

I have and it still does not work

1 Like

Does miniDonation.Activated:Connect(…) trigger it?

nope

Character limit

In that case, check your heirachy to verify script.Parent is indeed the textbutton. After that check that there isn’t maybe some sort of Z fighting going on between the button and the rest of the GUI that’s blocking the click.

If it still doesn’t work, as a test create a new button and attach just this script to it, does it work?

-- Place this code in a LocalScript in a TextButton
local textButton = script.Parent

local counter = 0
textButton.Text = "Click me!"

local function onActivated()
	counter = counter + 1
	textButton.Text = "Clicks: " .. counter
end

textButton.Activated:Connect(onActivated)

It seems that the problem is that the game is not proccessing the click as your script wont work and I have tested print statements on mine

Here’s what I just did and it works as expected.

Expanded my “StarterGUI” folder, clicked the + beside “ScreenGUI”, added a “TextButton”, clicked the + beside “TextButton”, added a “LocalScript”, pasted the above code (my example, taken from the documentation) into the LocalScript and saved it, pressed Play and clicked the button, each time it incremented.

If it works when setup as above, then the problem lies somewhere in your GUI setup.

1 Like

I’m using surface gui not screenGui

1 Like

Okay then, let’s do it with a SurfaceGUI.

If you follow the Interfaces for Parts it almost works for this case except you need to use a TextButton (with the script) vs a TextLabel.

To replicate:
Create a part call it poster, add a SurfaceGUI to it, add a Frame to that, add a TextButton then the script to the TextButton. Tweak values as needed, scale/offset/position. Create another part call it sign then set the posters SurfaceGUI “Adornee” property to the sign. Place the sign in the world. Drag the poster part into the “StarterGUI” folder. Press Play and click the button on the sign to register clicks.

My coffee level is currently below the “I should be posting instructions on the internet” threshold, but I think that should get you going in the right direction.

1 Like

Is the screenshot provided a LocalScript, or a Script with the RunContext set to Client? Since you’re using a SurfaceGui (which will have a parent in the workspace), a normal LocalScript wouldn’t work. If you haven’t done so already, try moving your code into a regular script and set its RunContext property to Client.

I’ve tested similar code, and this may be your problem.

1 Like

That’s what I thought at first, but it does indeed work with a LocalScript as shown in the above Interfaces for Parts example.

1 Like

Dw about it anymore I switched from a physical donating Board to a UI one and it works

1 Like

Put the surface gui in StarterGui, set the adornee to the donation board, then run your local script there (script also has to be in StarterGui)

1 Like

Yeah, if you have a LocalScript (in a client container) that handles a SurfaceGui under StarterGui and set its Adornee property to a specific part, that would also work.

Though, with no real problems in the code, l figured OP did not have this setup and that this may have been a case where the script was placed in a container where it wouldn’t run. To preserve their setup, what I previously suggested can be a solution, but the adornee route is the more organized one for sure.

1 Like

I’m going to solution this topic as I have redone my donation board as a fully UI menu.

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