MarketPlaceService Issue

MarketPlaceService Issue

Hey Scripters! I am making a donation board for one of my comms, and it runs off buttons on a surfacegui. Whenever someone clicks the button, instead of it showing for that one player, it shows for all players. It uses a server script as localscripts would not work. They use developer products and NOT gamepasses.

game.Players.PlayerAdded:Connect(function(plr)
	for i,v in pairs(script.Parent.ScrollingFrame:GetChildren()) do
		v.MouseButton1Click:Connect(function()
			local passid = v:GetAttribute('id')
			local price = v:GetAttribute('price')
			local userid = plr.UserId
			mps:PromptProductPurchase(plr, passid, true, Enum.CurrencyType.Robux)
			mps.PromptProductPurchaseFinished:Connect(function(userid, passid, ispurchased)
				if ispurchased then
                  print('more code here')
                end
            end)   
        end)
    end
end)

Obviously there is more but i wont show the full thing. If more is needed, I can present it.

Thanks! Reals_Dev

1 Like

store the necessary information (pass ID and price) when the button is clicked and use that information inside the PromptProductPurchaseFinished event handler. Here’s an adjusted version of your script:

luaCopy code

local mps = game:GetService("MarketplaceService")

game.Players.PlayerAdded:Connect(function(plr)
    for i, v in pairs(script.Parent.ScrollingFrame:GetChildren()) do
        v.MouseButton1Click:Connect(function()
            local passid = v:GetAttribute('id')
            local price = v:GetAttribute('price')

            -- Store the purchase information for the player who clicked the button
            local purchaseInfo = {
                PassId = passid,
                Price = price
            }

            -- Prompt the player to purchase the product
            mps:PromptProductPurchase(plr, passid, true, Enum.CurrencyType.Robux)

            -- Handle the purchase prompt finished event
            mps.PromptProductPurchaseFinished:Connect(function(userid, passid, ispurchased)
                if ispurchased and userid == plr.UserId then
                    -- Ensure the purchase is for the correct player
                    print('Player', plr.Name, 'purchased Pass', passid, 'for', price, 'Robux')
                    -- More code here
                end
            end)
        end)
    end
end)

In this version of the script, when a player clicks a button, the passid and price are stored in the purchaseInfo table. Then, within the PromptProductPurchaseFinished event handler, it checks whether the purchase was successful and whether it matches the correct player’s UserID before executing the intended code.

This should help ensure that the purchase prompt and subsequent actions are executed only for the player who clicked the button.

1 Like

This does not seem to have helped. Also I think you are fixing the wrong thing.

When the player clicks the button, it will prompt a purchase for ALL users inside the game. Whether they’ve pressed the button or not.

Issue Solved

Problem

The issue was i was calling it from a server script using a player added function.

Solved

Moving surfacegui into startergui so that the local script will work, and only fire it to that one player. (and making the adornee the part i want it to display on)

thanks to @ItsMuneeeb

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