Inventory System unequipping and equipping tool when pressing numpad- wrong behaviour

I am trying to make an inventory system, where pressing on your keyboard e.g numpad 1, 2,3 equips an item in that key slot. I have created a script to the point where the player can pick up interactable items, and they go into the slots.

The issue I have faced now is that on my server script when trying to DE-EQUIP the item that is selected to EQUIP the new item that has been pressed. (E.g if Item in #2 slot was selected previously, and numpad 3 was pressed to select #3, slot #2 would be de-selected and #3 would be in the players hand.

As seen in the GIF, when playing in studio the item equips and unequips at a random rate for no reason. I do not know how to explain the behaviour, but it looks to be both unequipping and equipping at the same time.

Any ideas?
RobloxStudioBeta_Emwp1u1ETI

— server script

local EquipRemote = game.ReplicatedStorage.Remotes.EquipTools
local Interactables = game.ReplicatedStorage:FindFirstChild("Interactables")

EquipRemote.OnServerEvent:Connect(function(plr, item)
    

    if plr.Backpack:FindFirstChild(tostring(item)) then
        print(item)
        print("is in backpack")
        local humanoid = plr.Character:FindFirstChild("Humanoid")
        local item = plr.Backpack:FindFirstChild(tostring(item))
        item.Parent = plr.Character

    
        
    elseif plr.Character:FindFirstChild(tostring(item)) then
        print(item)
        print("is in hand")
        item = plr.Character:FindFirstChild(tostring(item))
        item.Parent = plr.Backpack


    end
end)

–client

    if input.UserInputType == Enum.UserInputType.Keyboard then
        

        if input.KeyCode == Enum.KeyCode.B and not BackpackEnabled then
            print("backpack")
            BackpackUI.Parent.Visible = true;
            BackpackEnabled = true;
        elseif input.KeyCode == Enum.KeyCode.B and BackpackEnabled then
            BackpackUI.Parent.Visible = false;
            BackpackEnabled = false;
        end
        
        if Background:FindFirstChild(tostring(dictionary[input.KeyCode])) then
            local key = dictionary[input.KeyCode]
            local a = wordToNumber[key]
            print(a)
            local Item = ItemList[a]
            print(Item)
                
            if ItemList[a] ~= nil then
                --print(ItemList[a])
                EquipRemote:FireServer(Item)

            end
        else
            return

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

You’re spamming your keypad too much in the GIF; I cannot understand what you’re wanting to highlight in that GIF

No, I’m only pressing slowly. It rapidly re-equips when I unequip if that makes sense. I will send you another one

RobloxStudioBeta_XmQfKBJBth

I think your problem is Equipping and unequipping having the same Number Keys activating twice. In backpack to equip a tool you use the number(s) (default) and your system also uses the number(s) (to equip tools). Since the Initial Key fires it adds the tool to character and then yours fires (second) and puts it back in backpack.

Work with it or Prevent the tool being equipped Normaly.
This is what I found to Help: Help Removing Equip Tool With Number

Thanks for the response. I tried my best to understand what you said, my solution was to disable the coreUI general backpack. I still can’t make logical sense on why that occurs when the core UI is enabled, but i’m hoping that (as of currently i can see) by disabling the default backpack interface it solves my issue.

Apologies, glad that Disabling it worked. Some post stated that it didn’t help, so that’s good it did.

What I was trying to say is that, Pressing 1 will equip the tool in backpack by default, and your function also detects the Pressing of 1. So it’s firing two functions at the same time. One equipping the Item, the other Unequipping the item since it detects where the tool is. That’s why it’s rapid (instant).

So it’s just Interfering with Roblox’s Default Equip script that detects Pressing of 1-0. Which apparently disables when you disable the CoreGUI(BackPack), so that’s good.

I see. This makes perfect sense.

Thank you so much for all the help. You are a legend.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.