How to make a "buy" button when proximity?

Hey there! I want to make a “Buy” button where you’re at proximity to something. I think you need to use the thing called “Proximity Prompt” but as a noob developer I’m not sure.

Hope you can help me! Thanks!

If I do some grammaticals faults, sorry, I’m french and I’m not amazingly good at English :wink:

2 Likes

Wdym by proximity?

1 Like

When you’re near to the thing it print a “Buy” button and when you click “E” it print the buy panel (where, if you click Buy it use your Robux for buying it).

Hey! You already tried to use this one?
https://create.roblox.com/docs/reference/engine/classes/ProximityPrompt

1 Like

You can put proximity prompt in a part and put a local script in it with this code then i think it’ll work.

And also don’t forget to make RequiresLineOfSight option on proximityprompt “false” because you may not see the proximity prompt when ur near the part if its true.

If you want to edit the strings on the proximity prompt then you can change the ObjectText to the name of the thing like “2x Speed” or something and ActionText to “Buy”

local id = --gamepass id

script.Parent.Triggered:Connect(function()
	game.MarketplaceService:PromptGamePassPurchase(game.Players.LocalPlayer, id)
end)

This is my first reply on this forum either sorry if anything is wrong.

2 Likes

I tried the script but it seems like its not working on local script so you can just change the script to normal script and put this code in it.

local id = --gamepass id
local MarketPlace = game:GetService("MarketplaceService")
script.Parent.Triggered:Connect(function(player)
	MarketPlace:PromptGamePassPurchase(player, id)	
end)
2 Likes

Thanks for helping but oof I’m a noob dev and… I don’t understand, sorry. Can you explain? Thanks!

1 Like

No but I’ll try! Thanks for helping!

Just create a part and put a ProximityPrompt object in it, then put a Script in ProximityPrompt and paste the second code i’ve sent into that. Then You can edit the properties of ProximityPrompt to make it better. Like changing its ObjectText, ActionText, Hold Duration etc. And like i said ProximityPrompts also has an option which is named RequiresLineOfSight, making it false fixes the problem when you are not able to see the ProximityPrompt because its stuck in the part.

1 Like

I understood everything except this:

What script?

A normal script, just a script where we do the coding lol.
resim_2022-10-23_150202291

1 Like

Oh I thought you said I need to create two scripts. But I know how to create a script ofc :wink:

1 Like

Yeah sorry firstly i thought localscript would work because i used one in an UI but seems like it does not work in proximityprompt so i said to change the type of the script.

1 Like

I’ll try your script. I’ll tell you if it work! Also just one think, is this also working if I want to make a button for an UGC item instead of a gamepass?

1 Like

I haven’t tried it yet but probably yes, think you could find some videos of it on google.

1 Like

So it’ll work if I just replace the gamepass ID by the UGC ID, that’s it? (After this one I stop to ask you lot of questions :sweat_smile:)

1 Like

I don’t exactly know anything about UGC, so i can’t say anything useful. Also i don’t think it would work by changing the gamepass ID to UGC ID because it does not count as a gamepass so yeah, thats all from me lol.

1 Like

Ok. As I said I stop to ask questions. Thanks! :smiley:

1 Like

What exactly are u trying to sell?
Maybe you are looking for PromptProductPurchase() instead of gamepass
https://create.roblox.com/docs/reference/engine/classes/MarketplaceService

1 Like

Gamepass and UGC items, like shirts, pants or T-shirts.