Stock Donation and Tips Chests updating each other

Hi Everyone can you help me with this problem I have??? :wave: :wave:

I make DonationDev and also Tips where when I donate to one of them
For example if I donate to Tips 10 after Tips 10 displays 10. but why does DonationDev also add to that value??? so what’s wrong with this script?

Video

Code DonationDev — Script

local ProductID = 3230426474
local ProductPrice = 5
local CurrencyType = "Donate"
local MS = game:GetService("MarketplaceService")
local DS = game:GetService("DataStoreService"):GetDataStore("Places")

Debounce = true

if not DS:GetAsync(CurrencyType.."_RaisedDonate") then
	DS:SetAsync(CurrencyType.."_RaisedDonate",0)
end

Raised = DS:GetAsync(CurrencyType.."_RaisedDonate")
script.Parent.Parent.GuiS.GUI.TextS.Text = CurrencyType.." "..DS:GetAsync(CurrencyType.."_RaisedDonate")

function PrintOut(Value)
	print(Value)
end

script.Parent.Parent.PartSD.Attachment.ProximityPrompt.Triggered:connect(function(Player)
	if Debounce then
		if Player.userId > 0 then
			MS:PromptProductPurchase(Player,ProductID)
		end
	end
end)

MS.PromptProductPurchaseFinished:connect(function(UserId,ProductId,IsPurchased)
	if Debounce then
		Debounce = false
		if IsPurchased then
			DS:IncrementAsync(CurrencyType.."_RaisedDonate",ProductPrice)
			DS:OnUpdate(CurrencyType.."_RaisedDonate",PrintOut)
			script.Parent.Parent.GuiS.GUI.TextS.Text = CurrencyType.." "..DS:GetAsync(CurrencyType.."_RaisedDonate")
		end
		Debounce = true
	end
end)

coroutine.resume(coroutine.create(function()
	while wait() do
		Raised = DS:GetAsync(CurrencyType.."_RaisedDonate")
		script.Parent.Parent.GuiS.GUI.TextS.Text = CurrencyType.." "..DS:GetAsync(CurrencyType.."_RaisedDonate")
	end
end))

Code Tips— Script

local ProductID = 3230328106
local ProductPrice = 10
local CurrencyType = "Tips"
local MS = game:GetService("MarketplaceService")
local DS = game:GetService("DataStoreService"):GetDataStore("Places")

Debounce = true

if not DS:GetAsync(CurrencyType.."_RaisedTips") then
	DS:SetAsync(CurrencyType.."_RaisedTips",0)
end

Raised = DS:GetAsync(CurrencyType.."_RaisedTips")
script.Parent.Parent.GuiS.GUI.TextS.Text = CurrencyType.." "..DS:GetAsync(CurrencyType.."_RaisedTips")

function PrintOut(Value)
	print(Value)
end

script.Parent.Parent.PartSD.Attachment.ProximityPrompt.Triggered:connect(function(Player)
	if Debounce then
		if Player.userId > 0 then
			MS:PromptProductPurchase(Player,ProductID)
		end
	end
end)

MS.PromptProductPurchaseFinished:connect(function(UserId,ProductId,IsPurchased)
	if Debounce then
		Debounce = false
		if IsPurchased then
			DS:IncrementAsync(CurrencyType.."_RaisedTips",ProductPrice)
			DS:OnUpdate(CurrencyType.."_RaisedTips",PrintOut)
			script.Parent.Parent.GuiS.GUI.TextS.Text = CurrencyType.." "..DS:GetAsync(CurrencyType.."_RaisedTips")
		end
		Debounce = true
	end
end)

coroutine.resume(coroutine.create(function()
	while wait() do
		Raised = DS:GetAsync(CurrencyType.."_RaisedTips")
		script.Parent.Parent.GuiS.GUI.TextS.Text = CurrencyType.." "..DS:GetAsync(CurrencyType.."_RaisedTips")
	end
end))

In PromptProductPurchaseFinished, you don’t check if ProductId equals ProductID. Add this to the top of each connection, it should fix it.

if ProductId ~= ProductID then
   return
end

Also, you should almost always use ProcessReceipt instead of PromptProductPurchaseFinished. Roblox doesn’t intend that event to be used to process puchases.

1 Like

it works Thank you very much yeah I will use ProcessReceipt when I make something like that Thank you very much for your help :grinning: :grin: