In game part purchase button

so i did some steps a roblox website told me to do by creating in game purchases in the game settings under the monetization tab. now, all i want is a button that if u click it it buys it, in a part though not a gui. ive searched everywhere but only found gamepass gui buttons not actually in game purchase PARTS buttons

2 Likes

You would use ClickDetectors and the MouseClick event to prompt the player to purchase the game pass.

3 Likes

and does the script go in the part? and how do i script it? sorry i cant rlly script

1 Like

The ClickDetector goes inside the Part and the Script goes inside the Click Detector.

2 Likes

okay, is there anywhere i can find help with the script? i cant script but cant find anywhere that someone has a tutorial or has the script

1 Like

You can look at the code samples on the ClickDetector API Reference to help you script.

2 Likes

i dont understand a thing… can u help me

1 Like

I give you a sample.

local MarketplaceService = game:GetService("MarketplaceService")

ClickDetector.MouseClick:Connect(function(player)
    -- Prompt the gamepass to the player now
end)
1 Like

okay. so i guess the – line is where the purchase actually happens and where the ID goes?

Ez explained for u

local MSS= game:GetService("MarketplaceService")

ClickDetector.MouseClick:Connect(function(player)
    MSS:PromptGamePassPurchase(player.UserId,gamepassidhere)
end)

also watch : MarketplaceService | Documentation - Roblox Creator Hub

thats the thing, 1: whats the user id thing? if multiple people buy it there wont be a certain user id right? 2: it isnt a gamepass, its a ingame purchase, like those things u can buy multiple times (donations, in-game money) and so on

You prompt the player, not its UserId. It should be:

local MSS= game:GetService("MarketplaceService")

ClickDetector.MouseClick:Connect(function(player)
    MSS:PromptGamePassPurchase(player,gamepassidhere)
end)
local MSS= game:GetService("MarketplaceService")

ClickDetector.MouseClick:Connect(function(player)
    MSS:PromptProductPurchase(player.UserId,idhere)
end)

for u explained again: it gets the player if it clicks on the clickdetector (if ur using one)
2nd, player.UserId is needed bc it needs an 64 int value.

U prompt player.UserId or Player depends sometimes “Player” doesnt work^^

wait, okay so whos player id goes there, and also, can the purchase id go in the gamepass id place(which isnt a gamepass)


Please take a look, it says player-Instance, you don’t need the player’s UserId.

nvm hard to explain to u , I just send u a whole place where it has all the parts scripted ^^ , I feel like u started scripting 3 days ago.

so whats the script?? do i just remove the playerid part

The proper code will be:

local MSS = game:GetService("MarketplaceService")

ClickDetector.MouseClick:Connect(function(player)
    MSS:PromptProductPurchase(player,idhere)
end)
1 Like

There you go I made u a place : test.rbxm (3.0 KB)

local MSS= game:GetService("MarketplaceService")

local CD= script.Parent.ClickDetector

local idhere = 1090632600

CD.MouseClick:Connect(function(player)

MSS:PromptProductPurchase(player,idhere)

end)
1 Like