Spell cancel won't work

Henlo folks, I’m trying to create a system where you can cast a spell and cancel it before hand (with recasting). The issue is something in the local script causes me to spawn multiple string fields. I tried another method but it just delays everything, Any help would be appreciated.
Code (this code delays everything and you need to wait for it):

UIS = game:GetService("UserInputService")
local char = game.Players.LocalPlayer.Character
local on = false
local casted = false
local cd = false
local attack = 1
local plr = script.Parent



script.Parent.Equipped:Connect(function(Mouse)
	on = true
	script.Parent.Hold:FireServer(char,plr,on)
end)

script.Parent.Unequipped:Connect(function(mouse)
	on = false
	script.Parent.Hold:FireServer(char,plr,on)
end)
UIS.InputBegan:Connect(function(hol)
	if hol.UserInputType == Enum.UserInputType.MouseButton1 and on == true and cd == false then
		print("clicked")
		cd = true
		script.Parent.Attack:FireServer(char,plr,cd,attack)
		attack = attack + 1
		if attack >= 3 then
			attack = 1
		end
		wait(1.1)
		cd = false
	end
	if hol.KeyCode == Enum.KeyCode.Q and on == true and cd == false and casted == false then
		cd = true
		casted = true
		script.Parent.Skill1:FireServer(char,true,plr,script.Parent)
		print("added 1st attack")
		wait(10)
		cd = false
		casted = false
	end
	if hol.KeyCode == Enum.KeyCode.Q and casted == true then
			script.Parent.Skill1:FireServer(char,false,plr,script.Parent)
		print("removed first attack")
		wait(2)
		casted = false
	end
end)
UIS.InputEnded:Connect(function(hol)
	if hol.UserInputType == Enum.UserInputType.MouseButton1 and on == true then
		
	end
	if hol.KeyCode == Enum.KeyCode.Q and on == true and cd == true then
	end
end)

Could you add comments to your code, maybe above each if statement, and also to explain what your starting variables are used for?

This would help others better understand what you are trying to accomplish.