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
What is the issue? Problem is, that I currently have no clue how to make that happen. Very new to scripting.
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!
Remember, I want to learn, so don’t post finished code please Just some tips I want to figure it out myself.
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.
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?
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.