Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does my developer product duplicate?

Okay, so first off my developer product does not run off of a leaderstat. It runs off of an IntValue, which is parented to a StringValue. I currently have a developer product script that somewhat works. The stat that is given is credits. So basically, the first time I buy the product, say it's +250 credits. It works perfectly fine, and does its job. As soon as I buy it a second time though, it sort of duplicates the process, and instead of giving me 250 credits it gives me 750 credits. I have used this same exact script in another game and it worked perfectly fine. I have no idea what's wrong with it. Maybe the script possibly broke due to updates, I'm not really sure. If someone could help me out and tell me my problem. That would be very helpful.

Purchase Handler in ServerScriptService:

local MarketplaceService = Game:GetService("MarketplaceService")

local currency = "Credits" 

function SaveStats(player)
	player:SaveNumber(currency, player.Data:FindFirstChild(currency).Value)
end

local productId01 = 36951916
local productId02 = 36951930
local productId03 = 36951943
local productId04 = 36951963
local productId05 = 36951975
local productId06 = 36951986

MarketplaceService.ProcessReceipt = function(receiptInfo)
	local Player = Game.Players:GetChildren()
	for i = 1, #Player do
		if Player[i].userId == receiptInfo.PlayerId then
			prodId = tonumber(receiptInfo.ProductId)
			local h = Instance.new("Hint", Player[i])
			if prodId == productId01 then
				Player[i].Data:FindFirstChild(currency).Value = Player[i].Data:FindFirstChild(currency).Value + 250
			elseif prodId == productId02 then
				Player[i].Data:FindFirstChild(currency).Value = Player[i].Data:FindFirstChild(currency).Value + 500
			elseif prodId == productId03 then
				Player[i].Data:FindFirstChild(currency).Value = Player[i].Data:FindFirstChild(currency).Value + 1000
			elseif prodId == productId04 then
				Player[i].Data:FindFirstChild(currency).Value = Player[i].Data:FindFirstChild(currency).Value + 2500
			elseif prodId == productId05 then
				Player[i].Data:FindFirstChild(currency).Value = Player[i].Data:FindFirstChild(currency).Value + 5000
			elseif prodId == productId06 then
				Player[i].Data:FindFirstChild(currency).Value = Player[i].Data:FindFirstChild(currency).Value + 10000
			else
				h.Text = "Something went wrong."
				Game:GetService("Debris"):AddItem(h, 4)
				print("Something went wrong.")
				wait(1)
			end
			SaveStats(Player[i])
			h.Text = "Your stats have been saved! Thank you for purchasing!"
			Game:GetService("Debris"):AddItem(msg, 4)
		end
	end

	return Enum.ProductPurchaseDecision.PurchaseGranted
end

Script in the GUI button:

local MarketplaceService = Game:GetService("MarketplaceService")
local Player = Game.Players.LocalPlayer
local GUI = Player:WaitForChild("PlayerGui"):WaitForChild("DevShop")
GUI:WaitForChild("TextLabel")

local currency = "Credits"


local buyButton01 = GUI.TextLabel:WaitForChild("BuyGoldA")
local buyButton02 = GUI.TextLabel:WaitForChild("BuyGoldB")
local buyButton03 = GUI.TextLabel:WaitForChild("BuyGoldC")
local buyButton04 = GUI.TextLabel:WaitForChild("BuyGoldD")
local buyButton05 = GUI.TextLabel:WaitForChild("BuyGoldE")
local buyButton06 = GUI.TextLabel:WaitForChild("BuyGoldF")


local productId01 = 36951916 
local productId02 = 36951930 
local productId03 = 36951943 
local productId04 = 36951963
local productId05 = 36951975
local productId06 = 36951986


if Player.MembershipType == Enum.MembershipType.None then
	buyButton01.Text = "+250 " .. currency .. ""
	buyButton02.Text = "+500 " .. currency .. ""
	buyButton03.Text = "+1,000 " .. currency .. ""
	buyButton04.Text = "+2,500 " .. currency .. ""
	buyButton05.Text = "+5,000 " .. currency .. ""
	buyButton06.Text = "+10,000 " .. currency .. ""
else
	buyButton01.Text = "+250 " .. currency .. ""
	buyButton02.Text = "+500 " .. currency .. ""
	buyButton03.Text = "+1,000 " .. currency .. ""
	buyButton04.Text = "+2,500 " .. currency .. ""
	buyButton05.Text = "+5,000 " .. currency .. ""
	buyButton06.Text = "+10,000 " .. currency .. ""
end


buyButton01.MouseButton1Click:connect(function()
	if Player.MembershipType ~= Enum.MembershipType.None then
		MarketplaceService:PromptProductPurchase(Player, productId01, false, "Robux")
	else
		MarketplaceService:PromptProductPurchase(Player, productId01, false, "Tix")
	end	
end)

buyButton02.MouseButton1Click:connect(function()
	if Player.MembershipType ~= Enum.MembershipType.None then
		MarketplaceService:PromptProductPurchase(Player, productId02, false, "Robux")
	else
		MarketplaceService:PromptProductPurchase(Player, productId02, false, "Tix")
	end	
end)

buyButton03.MouseButton1Click:connect(function()
	if Player.MembershipType ~= Enum.MembershipType.None then
		MarketplaceService:PromptProductPurchase(Player, productId03, false, "Robux")
	else
		MarketplaceService:PromptProductPurchase(Player, productId03, false, "Tix")
	end	
end)

buyButton04.MouseButton1Click:connect(function()
	if Player.MembershipType ~= Enum.MembershipType.None then
		MarketplaceService:PromptProductPurchase(Player, productId04, false, "Robux")
	else
		MarketplaceService:PromptProductPurchase(Player, productId04, false, "Tix")
	end	
end)

buyButton05.MouseButton1Click:connect(function()
	if Player.MembershipType ~= Enum.MembershipType.None then
		MarketplaceService:PromptProductPurchase(Player, productId05, false, "Robux")
	else
		MarketplaceService:PromptProductPurchase(Player, productId05, false, "Tix")
	end	
end)

buyButton06.MouseButton1Click:connect(function()
	if Player.MembershipType ~= Enum.MembershipType.None then
		MarketplaceService:PromptProductPurchase(Player, productId06, false, "Robux")
	else
		MarketplaceService:PromptProductPurchase(Player, productId06, false, "Tix")
	end	
end)

4 comments

1

Uhh... you may not know, but you are using Data Persistence, which is already deprecated. Please use Data Stores instead: http://wiki.roblox.com/index.php?title=API:Class/DataStoreService Trust me, it is WAY better than the old way.

0

Also Tix isn't a thing anymore..

0

Would swapping to Data Store fix my problem with the duplicating?

0

I fixed the problem, thanks CStarLam for trying to help me out.

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.