Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Leaderboard Stats and Gamepasses not working?

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?

1 answer

✓ Accepted answer

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.

3 comments

0

Remember that connect and Game are deprecated aswell.

0

I changed 0 to the ID but it won't change the leaderstats

0

Oh, I edited. Check my new answer.

This discussion is preserved as it was. New answers, comments, and votes are closed.