SendNotification multiplying each time

Hey! I’m trying to send a notification (StarterGui:SetCore - SendNotification) on a ClientEvent callback. It does send the notification, however, it multiplies each time for some reason.

What I mean is that for the first time, it sends once. For the second time, it sends twice. For the 100th time, it would send the notification 100 times.

Any idea why that happens?

Trigger.MouseButton1Click:Connect(function()
	DataStoreEvent:FireServer(Players.LocalPlayer)
	DataStoreEvent.OnClientEvent:Connect(function(blacklisted)
		if blacklisted == false then
			-- unrelated script here
		elseif blacklisted == true then
			StarterGui:SetCore("SendNotification",{
				Title = "Blacklisted",
				Text = "Your access for the report system and handcuffs is removed!",
				Duration = 5,
			})
		end
	end)
end)
DataStoreEvent.OnServerEvent:Connect(function(targetPlayer)
	local blacklisted
	local success, errormessage = pcall(function()
		blacklisted = gameDataStore:GetAsync(targetPlayer.UserId)
	end)
	DataStoreEvent:FireClient(targetPlayer, blacklisted)
end)

On the client, for each click, you are making a new connection to the event. A quick fix for this would be changing :Connect to :Once for the data store OnClientEvent.

2 Likes

Either, you could do what @12345koip stated, or simply move the OnClientEvent outside of the function. Both have the same outcome.

1 Like

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