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.
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.)