ImageButton not working properly

Hi everyone,

I am making a basic SurfaceGui which has ImageButtons on it to purchase in game Points. Sadly, the code doesn’t appear to be working and I can’t see why…
Here is the code in the ImageButton:

MPS = game:GetService("MarketplaceService")
id = 974436122
local player = game.Players.LocalPlayer


function ButtonClicked()
	
	MPS:PromptProductPurchase(player, id)

end

script.Parent.Activated:Connect(ButtonClicked)

Here is the code in PurchaseHandler (located in Server Script Service):

MPS = game:GetService("MarketplaceService")

MPS.ProcessReceipt = function(receiptInfo)
	
	if receiptInfo.ProductId == 974436122 then
		local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		local points = player.leaderstats.Points
		
		points.Value = points.Value + 50
		
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end

the id for the product you prompt (id = 974436122) is different from the id you check in the ProcessReceipt callback (if receiptInfo.ProductId == 974435598 then)

Oh im sorry its because the store has different purchases and i just took the first ones that came. Its been fixed now, but thats not the problem. Somehow I can’t click on the buttons.

Maybe try say

local MPS = ...

and maybe it works if you just say

script.Parent.MouseButton1Click:Connect(ButtonClicked)

that is not the problem, MPS would still be the MarketplaceService even if it isnt a local var

for MouseButton1Click, it dont matter, Activated works just as well, and it is even recommended because MouseButton1Click is a misleading name, it detect input from mobile touch even tho it is named MouseButton1Click

@MrDaBigBoss but changing to MouseButton1Click could fix it because of this bug where if your button is in a scrolling frame, when its Zindex property is lower than ScrollingFrame’s Zindex, Activated will not work. if you want to use Activated, make the button Zindex higher than ScrollingFrame Zindex

I just tried that and it didn’t seem to have worked. Putting “local” in front of MPS didn’t work either

oh i just realised you use surfacegui. i did a search, and surfacegui have to be in game.Players.LocalPlayer.PlayerGui for input to work: Why won't buttons work on SurfaceGuis? - #5 by Rare_tendo

2 Likes

Thank you so much, although, how should I go about doing this? How can I put it in PlayerGui when it has to be on that surface?

SurfaceGui have an Adornee property, which you set to the part you want to put it on

it says in the last reply from the post i linked Why won't buttons work on SurfaceGuis? - #7 by MeaxisDev

1 Like

Thank you for your help, it finally works!