As soon as I put this in here. It starts over running other things?

So I have a script. And it works just fine. until I put some code in it that I need.
This script handles attacks.
And whenever I use one attack, its also registering the other attack.
Even though it should not.
When I have it like that It works just fine!

if keysDownTable['X'] and keysDownTable['S'] then
	print('Down attack')
	attackEvent:FireServer('DownAttack')
elseif keysDownTable['X'] and keysDownTable['W'] then
	print('Up attack, client')
elseif keysDownTable['X'] then -- this is where things go wrong.
	print('Hard attack, client')
				
end

But once I change it to this

if keysDownTable['X'] and keysDownTable['S'] then
	print('Down attack')
	attackEvent:FireServer('DownAttack')
elseif keysDownTable['X'] and keysDownTable['W'] then
	print('Up attack, client')
elseif keysDownTable['X'] then -- this is where things go wrong
	print('Hard attack, client')
	attackEvent:FireServer('ForwardAttack')
end

It just starts firing the attack anways.
I have no idea why this could be happening. I have checked all my other code and have narrowed it down so I know the problem is right here in this script.

Can anyone tell me why this is happening?

Full code
local uis = game:GetService('UserInputService')

local player = game:GetService('Players').LocalPlayer

local char = player.Character
wait(1)
local hum = char.Humanoid


local keysDownTable = {}


local function beginInput(input, gameProcessed)
	if not gameProcessed then
		if input.UserInputType == Enum.UserInputType.Keyboard then -- this is a keyboard
			print('SOMETHING PRESSED')
			
			local keysPressed = uis:GetKeysPressed()
			
			local keyCode = input.KeyCode
			print(keyCode)
			
			local attackEvent = game:GetService('ReplicatedStorage'):FindFirstChild('AttackEvents'):FindFirstChild('Attack')
			
			-- check for certain inputs
			if uis:IsKeyDown(Enum.KeyCode.X) and uis:IsKeyDown(Enum.KeyCode.W) then
				print('Keys X and W pressed')
				keysDownTable['W'] = Enum.KeyCode.W
				keysDownTable['X'] = Enum.KeyCode.X
			elseif uis:IsKeyDown(Enum.KeyCode.X) and uis:IsKeyDown(Enum.KeyCode.S)  then
				keysDownTable['S'] = Enum.KeyCode.S
				keysDownTable['X'] = Enum.KeyCode.X
			elseif uis:IsKeyDown(Enum.KeyCode.X)  then
				keysDownTable['X'] = Enum.KeyCode.X
			elseif uis:IsKeyDown(Enum.KeyCode.G) then
				
			elseif uis:IsKeyDown(Enum.KeyCode.Z) then
				
			elseif uis:IsKeyDown(Enum.KeyCode.R) then
				
			end
			
			-- now check for which inputs were detected
			print(keysDownTable) -- this has all the keys they pressed
			
			
			if keysDownTable['X'] and keysDownTable['S'] then
				print('Down attack')
				attackEvent:FireServer('DownAttack')
			elseif keysDownTable['X'] and keysDownTable['W'] then
				print('Up attack, client')
			elseif keysDownTable['X'] then
				print('Hard attack, client')
				attackEvent:FireServer('ForwardAttack')
			end
			
			-- remove items
			for n, item in pairs(keysDownTable) do
				print(n,item)
				keysDownTable[n] = nil
				print('Removing item' .. n,item)
			end
			
			-- items have been removed
		end
	end
end



local function endInput(input, gameProcessed)
	if not gameProcessed then
		if input.UserInputType == Enum.UserInputType.Keyboard then
			
			local keyCode = input.KeyCode
			

		end
	end
end



uis.InputBegan:Connect(beginInput)
uis.InputEnded:Connect(endInput)




It seems that the issue is with how you structured your conditionals. When you combine the “if” and “elseif” conditions for the “X” key, the code checks for each of these conditions in sequence. Once it finds the first matching condition, it will execute the corresponding code block and then move on to the next line of code.
In this case, the “X” key condition will always be true, since it is being checked last. This means that whenever the “X” key is pressed, it will execute both the “print” statement and the “FireServer” function call.
To fix this, you can switch the order of your conditions so that the two-attack conditions are checked before the single-attack condition. This will ensure that the script only executes one of the attack functions based on the combination of keys being pressed.

if keysDownTable[‘X’] and keysDownTable[‘S’] thenprint(‘Down attack’)attackEvent:FireServer(‘DownAttack’)elseif keysDownTable[‘X’] and keysDownTable[‘W’] thenprint(‘Up attack, client’)elseif keysDownTable[‘X’] thenprint(‘Hard attack, client’)attackEvent:FireServer(‘ForwardAttack’)end

Hope this helps, Mate

This is already what Im doing.
I check the X value last.
Isnt that what you’re saying