I've been making a simple RPG, and I want for players to be able to buy Gold and XP through gamepasses. I've tried this:
local productId = 0 -- change to your Gamepass product ID local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:connect(function() --DONT CHANGE THIS Game:GetService("MarketplaceService"):PromptPurchase(player, productId) end) from a free model gamepass GUI but it won't work! Can someone help?
First, please learn to use the code block, it's very useful and would tidy your code.
It would look like this:
local productId = 0 -- change to your Gamepass product ID local player = game.Players.LocalPlayer local name = "Gold" -- the name of the leaderstat item local reward = 500 -- the amount of the leaderstat awarded to the player after purchase game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:connect(function(p, gamepass, pur) if gamepass==productId then if game:GetService("Players"):FindFirstChild(p.Name) then game:GetService("Players"):WaitForChild(p.Name).leaderstats:WaitForChild(name).Value = game:GetService("Players"):WaitForChild(p.Name).leaderstats:WaitForChild(name).Value + reward end end end) script.Parent.MouseButton1Click:connect(function() --DONT CHANGE THIS game:GetService("MarketplaceService"):PromptPurchase(player, productId) end)
Also, the problem here is that productId
is 0.
When it says "change to your Gamepass product ID" it means that you should change the 0 to the id of the gamepass.
Try learning some basic Lua first, and you'll understand what I mean clearly.
So yeah, all you have to do is change the 0 to your gamepass's ID.