Gamepass script not working

I tried creating a gamepass where the player can get x2 coins.But it does not work

Script in SERVERSCRIPTSERVICE

local id = 25844191

game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
	if purchased and id == ido then
		plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value*2
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId, id) then
		plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value*2
	end
end)

Script in THE BUTTON:

local id = 25844191

script.Parent.MouseButton1Click:Connect(function()
	game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer, id)
end)

THE UP SCRIPT IS A LOCALSCRIPT

NO ERRORS TOO

Sorry for the capslock

I am unsure, but it looks as if you are just doubling the amount initially and being over with it. If the player joined with 10 coins, they’d get 20 and from there everything would be normal. You have to implement the doubling of earning coins in your other scripts too.

Have you tried print debugging your code? It will tell you where your code is stopping or if it is not running at all.

Uhm so where all should I add that line?

Actually it should only imply when the player has that gamepass not everywhere

Oh ya seems like a good idea let me try it

By everywhere, I mean where the player earns money. Currently, if the player has 0 and they buy the gamepass or join with the gamepass, they get 0. If they have 10 and buy the gamepass or join with the gamepass, they have 20. It doesn’t just apply in general, it is like a one-time “double your money” purchase that works every time you join. You would need to add this check wherever someone earns money. Alternatively, you could check how much money the player earned and double it, but I don’t recommend you do that.

so should I make a gamepass id variable and then put an if condition to check if he has gamepass in every earning script?

Ok then let me go with another gamepass thank you

So should I make yours as solution?

Ya I have seen all games with x2 coins for a timelimit but I thought I would change it but its fine

This probaly might be the problem

Yep. In every script that you have. Otherwise, you could have a system where it checks whenever the money update, and if the value increases, it subtracts from the previous one, gets the difference, and adds it again. If that solved your problem, do mark my reply as a solution. Hopefully I helped.

I don’t see a problem there. He is just checking if the gamepass purchased is the gamepass for x2 money. The problem lies within the code, as it doubles only once and never again.

local mps = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local plr = players.LocalPlayer
local button = script.Parent
local gamepassId = 25844191

button.MouseButton1Click:Connect(function()
	mps:PromptGamePassPurchase(plr, gamepassId)
end)
local players = game:GetService("Players")
local mps = game:GetService("MarketplaceService")
local gamepassId = 25844191

mps.PromptGamePassPurchaseFinished:Connect(function(plr, passId, wasPurchased)
	if wasPurchased then
		if passId == gamepassId then
			plr.leaderstats.Coins.Value *= 2
		end
	end
end)

players.PlayerAdded:Connect(function(plr)
	if mps:UserOwnsGamePassAsync(plr.UserId, gamepassId) then
		plr.leaderstats.Coins.Value *= 2
	end
end)

Remember that when the player joins their stat might be 0 so doubling it will result in the stat still being 0. These scripts will work providing the local script is placed inside the button and the server script is placed somewhere suitable like the ServerScriptService folder.

image

local players = game:GetService("Players")
local mps = game:GetService("MarketplaceService")
local gamepassId = 25844191

mps.PromptGamePassPurchaseFinished:Connect(function(plr, passId, wasPurchased)
	if wasPurchased then
		if passId == gamepassId then
			plr.leaderstats.Coins.Value *= 2
		end
	end
end)

players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr

	local coins =  Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Value = 100
	coins.Parent = leaderstats

	if mps:UserOwnsGamePassAsync(plr.UserId, gamepassId) then
		plr.leaderstats.Coins.Value *= 2
	end
end)

This is a server script with the leaderstats included, when I used it my coin stat was increased from 100 to 200 upon joining the game.

Pretty sure this is the same as his code, just reorganized and more efficient. The gamepass is supposed to give x2 the money you earn, not double it. This doesn’t do much apart from doubling the money whenever someone joins.

Oh, well in that case he’ll need to create a variable/instance value which represents whether or not a player has the gamepass, then whenever the coin stat is increased this can be checked and the coins awarded can be doubled/not doubled accordingly.

If you really don’t want to individually double each value earned, you could add a listener to the leaderstats value and double there. This would look like this:

As an individual script
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")

local DoubleMoneyGamepassId = 25844191

Players.PlayerAdded:Connect(function(Player)
	if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, DoubleMoneyGamepassId) then
	    local Coins = Player:WaitForChild("leaderstats"):WaitForChild("Coins")
	    local PreviousValue = Coins.Value
		Coins.Changed:connect(function()
		    local Difference = Coins.Value - PreviousValue
		    if Difference > 0 then
		        Coins.Value = Coins.Value + Difference
		    end
		end)
	end
end)
Inside your leaderstats declaration
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")

local DoubleMoneyGamepassId = 25844191

Players.PlayerAdded:Connect(function(Player)
	local Leaderstats = Instance.new("Folder")
	Leaderstats.Name = "leaderstats"
	Leaderstats.Parent = Player

	local Coins =  Instance.new("IntValue")
	Coins.Name = "Coins"
	Coins.Value = 100 -- However you get your values
	Coins.Parent = Leaderstats

	if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, DoubleMoneyGamepassId) then
	    local PreviousValue = Coins.Value
		Coins.Changed:connect(function()
		    local Difference = Coins.Value - PreviousValue
		    if Difference > 0 then
		        Coins.Value = Coins.Value + Difference
		    end
		end)
	end
end)

The only issue with this script is that it doubles the money EVERY time money are gained, so if someone earns money by killing another player or buys a developer product (such as +1,000 coins), it would double those two. Again, I recommend you go in and do individual checking on each script, but this could work if you don’t care about the two examples above.

Ok so what should I replace it with?

Wait no way how did you find my game?