Making a Double Coins Dev Product

How can I make a Timed Double Coins Dev Product. I tried making it like this

local part = script.Parent
local MarketplaceService = game:GetService("MarketplaceService")
local coins = 10
local exp = 15

local function processReceipt(receiptInfo)
	local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	print(player.Name .. " just bought " ..receiptInfo.ProductId)

if receiptInfo.ProductId == 1163195720 then
		coins *= 2
		wait(1800)
		coins = coins
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

MarketplaceService.ProcessReceipt = processReceipt

part.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if not plr or deb then return end

	local lstats = plr.leaderstats
	deb = true
	
	lstats.Coins.Value += coins
	lstats.Exp.Value += exp
	wait(1)
	deb = false
		
		
	end)

The script is meant to double how many coins they get for half an hour and then whenever they touch the part that gives them the coins it doubles it. When the player touches it the first time it does work, but then it starts going to much higher numbers and I don’t know what is wrong.

Try to set the deb as global variable and move deb = false in the part.TouchEnded event

1 Like

One issue I see is your usage of coins *= 2 and coins = coins. First player to buy the product will make the value 20. Second player to buy the product will then double that value, making it 40. Every time it is bought, the value is doubled what it currently is, not the base value. The value is never reset because you only set it to itself after the duration is over.

1 Like
if receiptInfo.ProductId == 1163195720 then
	coins *= 2
	wait(3600)
	coins = 10
end

I changed it so now it resets back to 10 but i still don’t know how to double the base value

local baseCoins = 10
local coins = baseCoins

if receiptInfo.ProductId == 1163195720 then
	coins = baseCoins * 2
	wait(3600)
	coins = baseCoins
end