My developer product only works once

Hello. I have an issue with a developer product, basically you can only buy it once, then if you try to purchase it again it will take your robux but give you no more in-game currency.

here is the “handler” script

local DataStoreService = game:GetService("DataStoreService")
local LeaderstatDataStore = DataStoreService:GetDataStore("LeaderstatDataStore")

local DeveloperProductID = 1597899398 -- my id

game.Players.PlayerAdded:Connect(function(player)
	local Leaderstat = player.leaderstats.FairyDust

	local LeaderstatKey = player.UserId .. "FairyDust"
	local success, savedValue = pcall(function()
		return LeaderstatDataStore:GetAsync(LeaderstatKey)
	end)
	if success and savedValue then
		Leaderstat.Value = savedValue
	end

	local Purchased = false

	game:GetService("MarketplaceService").ProcessReceipt = function(receiptInfo)
		if receiptInfo.PlayerId == player.UserId and receiptInfo.ProductId == DeveloperProductID and not Purchased then
			Purchased = true

			Leaderstat.Value = Leaderstat.Value + 250

			local Success, error = pcall(function()
				LeaderstatDataStore:SetAsync(LeaderstatKey, Leaderstat.Value)
			end)
			if not Success then
				warn("Failed to save leaderstat data:", error)
			end
		end
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end)

Please help

1 Like

Sorry for no answer. Im working on it, hold on.

Leaderstat.Value += 250

Try this.

This does not work for some reason. I really dont know whats wrong

its because Purchased is set to true and never set back to false

1 Like

so do i just put purchased = false at the end

you dont really need a purchased variable, but you can still do that

would this fix the issue tho?

1 Like

mhm, it used to work only once cuz the Purchased Variable was kept set to true and never set back to false,
but as i said you dont really need a purchased value

It works at least for now. thank you

1 Like

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