Script is equipping a tool without instructions to do so

Hello, I’m working on a custom backpack for my game but I’m running into a couple issues. The basis of my script is a LocalScript, ServerScript, NumberValue, and a RemoteEvent.
image

The server script is messing up though, it is absolutely refusing to unequip tools, I even tried cloning the tools and deleting the previous one but it still did nothing.

Every print is printing but it’s still refusing to unequip, what’s the issue?

Here’s the local script, not the issue.

local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer

UIS.InputBegan:Connect(function(input, GPE)
	if GPE then return end
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.Q then
			script.WeaponEquipRE:FireServer(player)
			print("sent")
		end
	end
end)

And here’s the server script, the issue.

local tool

script.Parent.WeaponEquipRE.OnServerEvent:Connect(function(player)
	print("caught")
	if script.Parent.WeaponEquippedNumber.Value == 3 then -- Equip weapon1
		tool = script.Parent.Parent.weaponlibrary.Weapon1:FindFirstChildWhichIsA("Tool")
		player.Character.Humanoid:EquipTool(script.Parent.Parent.weaponlibrary.Weapon1:FindFirstChildWhichIsA("Tool"))
		script.Parent.WeaponEquippedNumber.Value = 2
		print("equippedweapon1")


	elseif script.Parent.WeaponEquippedNumber.Value == 2 then -- Equip weapon2
		tool = script.Parent.Parent.weaponlibrary.Weapon2:FindFirstChildWhichIsA("Tool")
		tool.Parent = player.PlayerGui.weaponlibrary.Weapon1
		player.Character.Humanoid:EquipTool(script.Parent.Parent.weaponlibrary.Weapon2:FindFirstChildWhichIsA("Tool"))
		script.Parent.WeaponEquippedNumber.Value = 1
		print("equippedweapon2")


	elseif script.Parent.WeaponEquippedNumber.Value == 1 then -- unequip all weapons
		tool.Parent = player.PlayerGui.weaponlibrary.Weapon2
		script.Parent.WeaponEquippedNumber.Value = 3
		print("unequipped weapons")
	end
end)

How it’s supposed to work is that there’s a number, the number will go down and reset on the third key press. On the first key press it should equip the weapon in WeaponSlot1, then WeaponSlot2, then unequip both so you have empty hands.

For reference, it should be unequipping both tools on the third key press (third print), instead, it is acting as if the WeaponEquippedNumber == 3 when it equals 1. (I checked, it does equal 1 on the value in-game.)

deathwatch tech - Roblox Studio (gyazo.com)

ok i think i got something working (i tried to clean up your code a bit, make any tweaks or changes that are incorrect):

local WeaponEquippedNumber = script.Parent.WeaponEquippedNumber
local tool

script.Parent.WeaponEquipRE.OnServerEvent:Connect(function(player)
	print("caught")
	WeaponEquippedNumber.Value += 1
	-- This allows all weapons to be unequipped on 3rd press
	if WeaponEquippedNumber.Value >= 4 then WeaponEquippedNumber.Value = 1 end
	
	if WeaponEquippedNumber.Value == 1 then -- All weapons unequipped
		tool.Parent = player.PlayerGui.weaponlibrary.Weapon2
	elseif WeaponEquippedNumber == 2 then -- Equip weapon 1 
		tool = script.Parent.Parent.weaponlibrary.Weapon1:FindFirstChildWhichIsA("Tool") -- Get weapon 1 
		player.Character.Humanoid:EquipTool(tool) -- automatically equip weapon 1
	elseif WeaponEquippedNumber == 3 then -- Equip weapon 2 
		tool.Parent = player.PlayerGui.weaponlibrary.Weapon1 -- Put weapon 1 back into storage (i think)
		tool = script.Parent.Parent.weaponlibrary.Weapon2:FindFirstChildWhichIsA("Tool") -- Get weapon 2
		player.Character.Humanoid:EquipTool(tool) -- automatically equip weapon 2
	end
end)

but try this and see if it works

though i didnt test to make sure it works sooo :+1::+1::+1::+1::+1::+1::+1::+1::+1::+1::+1::+1::+1::+1::+1::+1::+1::+1::+1::+1:

Thank you, I’ve decided to try another way entirely though.

okkkkkkkkkkkkkkkkkkkkk

(post has to have at least a certain amount of characters :/)