Player.Chatted is printing twice. Why?

I’m using player.chatted for a spell system but it seems to get the player chat twice which messes up the notification system and it gives you a notification saying the spell is on cooldown when you type the spell.

local ClickEvent
function WitchSpell(message,spellName,spell)
	if IsSpecie({"Vampire","Original","WereWolf","Hybrid"}) == true then return end
	local spellName = string.lower(message)
	local spell = SpellSystem.Spells[spellName]
	if spell == nil then return end
	if spell.OnCooldown == true then local smessage = (spellName.." is on cooldown") NotificationServer:FireServer(player,smessage,"Cooldown")  return end
	local Distance = spell.Distance
	if player.Character:FindFirstChild("MagicDisabled") then NotificationServer:FireServer(player,"Your magic has been disabled","Magic Disabled") return end
	if IsGhost(player) == true then NotificationServer:FireServer(player,"You can't cast spells as a spirit","The Other Side") return end
	if IsRagDolled(player) == true then return end
	
	--[[
	local Spell1 = "faire a voir la re "
	local Spell2 = "adducere eos "



	if message:sub(1, Spell1:len()):lower() == Spell1:lower() then
		local Message = message:sub(Spell1:len() + 1)
		if SpellSystem.Spells["faire a voir la re"].OnCooldown == false then
			SpellSystem.Spells["faire a voir la re"].OnCooldown = true
			local SpellName = "faire a voir la re"
			WitchSpellEvent:FireServer(SpellName,Message)
			wait(SpellSystem.Spells["faire a voir la re"].Cooldown)
			SpellSystem.Spells["faire a voir la re"].OnCooldown = false
		end
	end
	if message:sub(1, Spell2:len()):lower() == Spell2:lower() then
		local Message = message:sub(Spell2:len() + 1)
		if SpellSystem.Spells["adducere eos"].OnCooldown == false then
			SpellSystem.Spells["adducere eos"].OnCooldown = false
			local SpellName = "adducere eos"
			WitchSpellEvent:FireServer(SpellName,Message)
			wait(SpellSystem.Spells["adducere eos"].Cooldown)
			SpellSystem.Spells["adducere eos"].OnCooldown = false
		end
	end
	--]]

	

	if  CharacterConfig.Magic.Value < spell.Magic then
		spell.OnCooldown = false
		local num = spell.Magic - CharacterConfig.Magic.Value
		local msg = ("You need "..tostring(math.round(num)).." more magic to cast "..spellName)
		ClickEvent:Disconnect()
		NotificationServer:FireServer(player,msg,"Low Magic")
	end

	if spell.Input == Enum.UserInputType.TextInput then
		WitchSpellEvent:FireServer(spellName)
		spell.OnCooldown = true
		wait(spell.Cooldown)
		spell.OnCooldown = false
	end

ClickEvent = Mouse.Button1Down:Connect(function(Input,Processed)
		if spellName == "fiate fulguris" and (player.Character.HumanoidRootPart.Position - Mouse.Hit.Position).Magnitude <= Distance and IsCharacter(Mouse.Target.Parent) == true then
			local Target = Mouse.Target.Parent
			ClickEvent:Disconnect()
			Replicated.Assets.Remotes.Ability:FireServer('Lightning',Mouse.Hit)
			CamShake:Start()
			CamShake:Shake(CameraShaker.Presets.Lightning)
			WitchSpellEvent:FireServer(spellName,Mouse.Target.Parent)
			
			spell.OnCooldown = true
			wait(spell.Cooldown)
			spell.OnCooldown = false
		end

		if spell.Input == Enum.UserInputType.MouseButton1 or spell.Input == Enum.UserInputType.Touch then
				if  (player.Character.HumanoidRootPart.Position - Mouse.Hit.Position).Magnitude <= Distance and IsCharacter(Mouse.Target.Parent) == true  then 
					if IsCharacter(Mouse.Target.Parent) == false then ClickEvent:Disconnect() return end
					local Target = Mouse.Target.Parent
					ClickEvent:Disconnect()
				WitchSpellEvent:FireServer(spellName,Mouse.Target.Parent)
				spell.OnCooldown = true
				wait(spell.Cooldown)
				spell.OnCooldown = false
				end
		end	
	end)	
end

player.Chatted:Connect(WitchSpell)

This is not set to true.
And why do you need a cooldown?

The player.Chatted event can sometimes receive the player chat message more than once, which can lead to unexpected behavior in your spell system. One way to fix this is by disconnecting the event listener after the spell is cast, and then reconnecting it after the spell’s cooldown has ended.

Here’s an example of how you could modify your WitchSpell function to achieve this:

local function WitchSpell(message)
    -- your existing code here

    -- disconnect the event listener
    player.Chatted:Disconnect()

    -- wait for the spell cooldown to end
    wait(spell.Cooldown)

    -- reconnect the event listener
    player.Chatted:Connect(WitchSpell)
end

With this modification, the player.Chatted event will only trigger the WitchSpell function once per spell cast, even if the event fires multiple times for the same chat message.

So a player can’t spam the spell.

I tried this and it’s still printing twice.