Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Leaderboard Stats and Gamepasses not working?

Asked by 7 years ago
Edited 7 years ago

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

Log in to vote
0
Answered by
luadotorg 194
7 years ago
Edited 7 years ago

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.

0
Remember that connect and Game are deprecated aswell. PyccknnXakep 1225 — 7y
0
I changed 0 to the ID but it won't change the leaderstats Welovegod1029384756 25 — 7y
0
Oh, I edited. Check my new answer. luadotorg 194 — 7y
Ad

Answer this question