Problem with developer product

Making a global announcement developer product, the first purchase works perfectly but the second time I buy it it does the announcement before even being purchased it just announces it in the second purchase of it, Any idea on how to fix that?
Script:

local RS = game:GetService("ReplicatedStorage")
local GA = RS.GlobalAnnouncement
local A = RS.Announcement
local MPS = game:GetService("MarketplaceService")
local Id = 1278759987


local function GAE()
	GA.OnServerEvent:Connect(function(player, text)
		script.Parent.Text = text
	end)
end
	
MPS.ProcessReceipt = function(receiptinfo)
	local player = game.Players:GetPlayerByUserId(receiptinfo.PlayerId)
	if not player then
			return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	if receiptinfo.ProductId == Id then
		print(receiptinfo)
		GAE()
		end
		return Enum.ProductPurchaseDecision.PurchaseGranted
end

Local Script:

local Announcement = game.StarterGui.Announcement.Announcement
local MPS = game:GetService("MarketplaceService")
local Id = 1278759987

--[[local function Opening()
	Announcement:TweenPosition(
		UDim2.new(0.281, 0, 0.037, 0),
		"Out",
		"Bounce",
		0.5,
		false
	)
end
local function Closing()
	Announcement:TweenPosition(
		UDim2.new(-0.5, 0, 0.037, 0),
		"Out",
		"Bounce",
		0.5,
		false
	)
end
]]



script.Parent.MouseButton1Up:Connect(function()
	local textbox = script.Parent.Parent.TextBox.Text
	GA:FireServer(textbox)
	A:FireServer()
	MPS:PromptProductPurchase(Player, Id)
end)

It’s because the 2nd time it’s ran, the OnServerEvent still exists, you have to disconnect it

local event
local function GAE()
	event = GA.OnServerEvent:Connect(function(player, text)
		script.Parent.Text = text
        event:Disconnect()
	end)
end

Though not sure if this is the best approach seeing as how you’re doing Gui work on the server when it’s usually done on clients, Recommend more of a FireAllClients, OnClientEvent approach instead

1 Like

It sadly gave a error on “Disconnect”, And the other way you recommended it would have to be a 3 way communication but trust me I used it before and the same problem happened so I ignored it but this time I wanna solve it.

That’s odd, when does it error, before/after first purchase or during the 2nd purchase?

Apparently it’s during the first purchase

If you’re just going to wait for it to be called and then just disconnect it, you can use :Wait() instead for this event.

https://www.roblox.com/library/8238899977/Boards-thingy

This is a donation board that you have to click on it in oder to get the solution, maybe.

Man it works now, Thank you so much! :slight_smile: