Need help with making a game pass prompt

  1. What do you want to achieve? GUI Button, that when clicked prompts player to purchase a gamepass, and when purchased it puts a part in the game world that shows just for that one player

  2. What is the issue? Problem is, that I currently have no clue how to make that happen. Very new to scripting.

  3. What solutions have you tried so far? I have tried looking for answer but so far haven’t found any, if you find something then please let me know! :slight_smile:

Remember, I want to learn, so don’t post finished code please :slight_smile: Just some tips :smiley: I want to figure it out myself.

3 Likes

Use the UserOwnsGamePassAsync to check if the player owns the gamepass. So whenever the UI button is clicked, you will make the check and if it returns true, you will add the part. Since the part is only visible to the Client, everything could be handled locally.

2 Likes

Ok, thanks! I have a feeling that this will be a bit too complicated for me to do without any tutorials :smiley: But I’ll give it a try for sure

1 Like

Try looking at these 2 articles Passes | Documentation - Roblox Creator Hub and TextButton | Documentation - Roblox Creator Hub

3 Likes

Thanks! I’ll try, wish me luck lol

1 Like

I got the button to work and prompt the developer product purchase. But now I want to make it so it offers a different product for each “room” the player is in.

This seems to work so far

	if player.leaderstats.Room.Value == 1 then
		local player = Players.LocalPlayer
		MarketplaceService:PromptProductPurchase(player, productID1)
	end
end	

But, is there a way to make it more simple? Let’s say there is 20 rooms or even more, how should I do that?

1 Like

What I would do is make a dictionary that contains every gamepass id for each room, and I would also prefix them with the same thing, for example each index would start with RoomID. Then afterwards, I would change the code to

local roompasses = {
   roomID1 = 158374683,
   roomID2 = 158648694
   --And so on, replace with your own ids
}

if roompasses["roomID"..player.leaderstats.Room.Value] then
		local player = Players.LocalPlayer
		MarketplaceService:PromptProductPurchase(player, roompasses["roomID"..player.leaderstats.Room.Value])
	end
end	

Hopefully code like this should work as if there exists a value in the dictionary then it will prompt the purchase, if it doesn’t exist then nothing will happen (which from the looks of it, you’re prompting a dev product rather than a gamepass, change PromptProductPurchase to PromptGamePassPurchase if you want to prompt a gamepass). Hopefully I didn’t make any mistakes.

3 Likes

Ohhhh! Thats a clever way to do it! Thanks, I’ll try! :slight_smile:

1 Like

Good luck! I’m not sure what’ll happen since I didn’t test it out and just thought of it, but if anything goes wrong, I’ll be here to help out!

At least it looks like it would work :smiley: I’ll let you know what happens

Alright, good luck with changing the code! And if it looks a bit confusing, I could try to give a more explanation as to what’s going on in that code

Works like a charm! Thank you, that was really helpful!! :slight_smile:

Anytime! If you need anymore help don’t be afraid to make another post!