I made my own Hotbar system, and it worked perfectly, but when I went to try to unequip by pressing the same key I used to equip I couldn't. Could someone help me track down, and solve this problem? Here's my script:
local Players = game:GetService("Players").LocalPlayer
local UI = script.Parent.HotbarFrame
local Keys = {
["One"] = "1",
["Two"] = "2",
["Three"] = "3",
["Four"] = "4",
["Five"] = "5",
["Six"] = "6",
["Seven"] = "7",
["Eight"] = "8",
["Nine"] = "9",
}
local Tools = {}
local SlotSelected = 0
game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
function KeySelected(Slot)
for i,v in pairs(UI:GetChildren()) do
if v:IsA("ImageButton") then
v.outline.Visible = false
v.ToolName.TextColor3 = Color3.fromRGB(255, 255, 255)
end
end
for i,v in pairs(Players.Character:GetChildren()) do
if v:IsA("Tool") then
v.Parent = Players.Backpack
end
end
for i,v in pairs(Tools) do
if not v:FindFirstChild("SlotName") then return end
if v.SlotName.Value == Slot.Name then
v.Parent = Players.Character
end
end
SlotSelected = tonumber(Slot.SlotName.Text)
Slot.outline.Visible = true
Slot.ToolName.TextColor3 = Color3.fromRGB(255, 0, 0)
end
function ConvKeyCode(KeyCode)
for i,v in pairs(Keys) do
if KeyCode == Enum.KeyCode[i] then
if UI:FindFirstChild("Slot"..v) then
KeySelected(UI["Slot"..v])
else
print("Slot"..v, false)
end
end
end
end
Players.Backpack.ChildAdded:Connect(function(Child)
Tools = {}
for i,v in pairs(Players.Backpack:GetChildren()) do
if v:IsA("Tool") then
table.insert(Tools, v)
if not v:FindFirstChild("SlotName") then return end
if UI:FindFirstChild(v.SlotName.Value)then
UI:FindFirstChild(v.SlotName.Value).ToolName.Text = v.Name
end
end
end
end)
game:GetService("UserInputService").InputBegan:Connect(function(Input)
ConvKeyCode(Input.KeyCode)
end)

2 comments
Which part of your code is responsible for unequipping?
I didn't add, Could you help me add it. I do not know what I should do