How do i fix this script?

Im sorry, im not sure how to explain it but how do i make this script only do something when the the gui is clicked. Here so basically when a player clicks on a new skill and equips it in for example slot 1, it is equipped in slot 1, but when that player equips something slot 2 it just breaks. Im pretty sure i know why but im not good at explaining, or preventing

local keyWordTable = {
	["AttackKey"] = Enum.KeyCode.E 
}

local slot1connect, slot2connect

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Values.Triggered.Value = true
	if slot1connect then slot1connect:Disconnect() end
	if slot2connect then slot2connect:Disconnect() end
	slot1connect = Slot1.MouseButton1Click:Connect(function()
		
		keyWordTable["AttackKey"] = Enum.KeyCode.Q
	end)

	slot2connect = Slot2.MouseButton1Click:Connect(function()
	
		keyWordTable["AttackKey"] = Enum.KeyCode.E
	end)
end)

So like when i click the equip button for slot 1 the skill equips but when i equip a new skill in the same slot they just combine same with the other slot. Im pretty sure it’s because both scripts use the same equip menu to equip different skills

Well, if you found the problem, why don’t you just fix it?

i found the problem, but im not sure how to fix it

You said the problem is because all the slots have their own script. Then, just make a new script and make that script control all the slots.

Please don’t make posts that is the exact same as another one.
Post.

sorry i was just desperate on finding a solution, really sorry

it’s just that when a player equips an item they both use the same gui and when they click the gui the skill’s script both combine, or something like that

Yeah, so you need to create a singular script which controls all the slots so they don’t “mix” each others.

but how would that do anything? wouldn’t that cause the same problem? (not to be rude)