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?
— 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.