Script is quadrupling a value instead of doubling it?

Hey there, so I’m trying to get this developer product to 2x your leaderstat called “Time” it functions completely fine but instead of doubling it, its quadrupling it, I did some basic maths to figure this out

The script is parented to a folder under workspace, should be no issues.

Here is the code:

local datastoreService = game:GetService("DataStoreService")

local mps = game:GetService("MarketplaceService")

local player = game:GetService("Players")

local datastore = datastoreService:GetDataStore("Time")

local devproductid = 1621734615

game.Players.PlayerAdded:Connect(function(player)
	mps.ProcessReceipt = function(receiptInfo)
		if receiptInfo.ProductId == devproductid then
			player.leaderstats.Time.Value = player.leaderstats.Time.Value * 2
		end
	end
end)

I’ve gotten no errors within the output.

I’ve tried adding the current value onto it but it still does it. I tried doing it by instead of “player.leaderstats.Time.Value = player.leaderstats.Time.Value * 2” I did: “player.leaderstats.Time.Value = player.leaderstats.Time.Value + player.leaderstats.Time.Value”

Any help is appreciated.

I might be a bit dumb as I’m not a math wizard so this could just be a silly mistake but still help is appreciated.

I’ve just realised, its not always doing it, sometimes it does double it but sometimes is quadruples it, now I’m very confused.

1 Like

Is there any reason you’re using playerAdded versus an event, like actually prompting the purchase?

The prompting pruchase is done within a local script within a screen gui.

Everything works fine its just the values arent doing what I think they should be doing.

I would say that’s probably your issue. Fire a remote when the button is pressed and prompt the purchase on the server, as well as handling everything there versus in a playerAdded event and tell me how that works :slight_smile:

Okay, Ill go ahead and give that a try.

Also, I just realized that in this line

local player = game:GetService("Players")

You’re defining the player as Game.Players, which could be causing some weird interference as well.
(There’s no need for this variable as it seems you are using game.Players.PlayerAdded either way)

make sure Enum.ProductPurchaseDecision.PurchaseGranted

read this(scroll everything down)

Oh yeah i just realised that, Ill see if that could make a difference.

I do this under the original if statement and using return dont I?

You’re using if receiptInfo.ProductId == devproductid then which is different.

I added this and its working, I forgot you had to add this thanks for the help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.