Equipping/Unequipping Tool Problem

  1. What do you want to achieve? I want a tool that equips when you hit 1 and unequip when you hit 2 or 3 or 4 or 5 but not when you press anything else.

  2. What is the issue? The tool unequips when you hit anything instead of only 2, 3, or 4,


local One = Enum.KeyCode.One
local Two = Enum.KeyCode.Two
local Three = Enum.KeyCode.Three
local Four = Enum.KeyCode.Four
local Five = Enum.KeyCode.Five
local Key = Enum.KeyCode

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == One then
		for i,v in pairs(PlayerBackpack:GetChildren()) do
			if v.Name == Backpack[1] then
				Character.Humanoid:EquipTool(v)
				print(v.Name)
				UserInputService.InputBegan:Connect(function(input)
					if input.KeyCode == Two or Three or Four or Five then
						Character.Humanoid:UnequipTools(v)
					else
						print("Not equiv to []")
						Character.Humanoid:EquipTool(v)

					end

				end)

			end
		end
	end
end)



1 Like

try changing this to

if input.KeyCode == Enum.KeyCode.One then

The reason it says One is because I have a variable for it.

local One = Enum.KeyCode.One
local Two = Enum.KeyCode.Two
local Three = Enum.KeyCode.Three
local Four = Enum.KeyCode.Four
local Five = Enum.KeyCode.Five
local Key = Enum.KeyCode

Try this:

if input.KeyCode == Two or input.KeyCode = Three or input.KeyCode = Four or input.KeyCode = Five then

I suggest you use a table to shorten your code. Either way, it should work.

1 Like