Event firing multiple times?

So I have a script that runs multiple times depending on how many times they have dont that,
which is not what I want, I want it to only do it once,

Btw it does it twice if the player has called the function twice, once if the called it once, etc.

So how would I fix this?

I also know that it is happening on the client, or at least I think

Client

promt2.Triggered:Connect(function()
	local frame = script.Parent.PlayRecording
	
	frame.Visible = true
	frame.TextButton.Activated:Connect(function()
		if frame.NameBox.ContentText ~= nil and frame.NameBox.ContentText ~= ' ' then
			-- then it is a name so we can send it to the server
			local event = game:GetService('ReplicatedStorage'):FindFirstChild('ViewRecording')

			event:FireServer(frame.NameBox.ContentText)

			frame.Visible = false
		end
		return
	end)
end)

Server

eventRecord2.OnServerEvent:Connect(function(player,name)
	-- check for recording
	warn('Looking for recording')
	if recordings[name] then
		displayRecording(recordings[name])
	else
		warn('Recording not found')
	end
end)

Thanks!

Can’t provide an accurate piece of code for you but every time promt2 gets triggered, the textbutton gets connected to a function. so when the promt2 is triggered twice, then the textbutton is connected twice, making it run twice for one click.

1 Like

Oh, that makes sense.
I have done something like this and I know how to fix it so thanks!