Hello I’m working on a game based on booga booga and I have a issue with my hotbar system
How do I make it so the items don’t disappear in backpack when equipped to character
Code:
local hotbar = script.Parent:GetChildren()
game:GetService('StarterGui'):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
local lastnum = nil
local equip = {
[1] = false,
[2] = false,
[3] = false,
[4] = false,
[5] = false,
[6] = false
}
local nums = {
[1] = "One",
[2] = "Two",
[3] = "Three",
[4] = "Four",
[5] = "Five",
[6] = "Six"
}
local inputservice = game:GetService("UserInputService")
inputservice.InputBegan:Connect(function(input, gameprocessed)
if input.KeyCode == Enum.KeyCode.One then
print("e")
script.Parent.invsound:Play()
if equip[lastnum] ~= nil and lastnum ~= 1 then
equip[lastnum] = false
print(equip[lastnum])
end
equip[1] = not equip[1]
if equip[1] == true then
game.Players.LocalPlayer.Character.Humanoid:EquipTool(script.Parent["1"].obj.Value)
else
game.Players.LocalPlayer.Character.Humanoid:UnequipTools()
end
lastnum = 1
print(equip[1])
print(equip)
end
end)
inputservice.InputBegan:Connect(function(input, gameprocessed)
if input.KeyCode == Enum.KeyCode.Two then
print("e")
script.Parent.invsound:Play()
if equip[lastnum] ~= nil and lastnum ~= 2 then
equip[lastnum] = false
print(equip[lastnum])
end
equip[2] = not equip[2]
if equip[2] == true then
game.Players.LocalPlayer.Character.Humanoid:EquipTool(script.Parent["2"].obj.Value)
else
game.Players.LocalPlayer.Character.Humanoid:UnequipTools()
end
lastnum = 2
--if equip[lastnum] == true then
--script.Parent:FindFirstChild(lastnum).BackgroundColor3 = Color3.fromRGB(24, 225, 255)
--else
--script.Parent:FindFirstChild(lastnum).BackgroundColor3 = Color3.fromRGB(104,104,104)
--end
--print(equip[lastnum])
print(equip[2])
print(equip)
end
end)
inputservice.InputBegan:Connect(function(input, gameprocessed)
if input.KeyCode == Enum.KeyCode.Three then
print("e")
script.Parent.invsound:Play()
if equip[lastnum] ~= nil and lastnum ~= 3 then
equip[lastnum] = false
print(equip[lastnum])
end
equip[3] = not equip[3]
if equip[3] == true then
game.Players.LocalPlayer.Character.Humanoid:EquipTool(script.Parent["3"].obj.Value)
else
game.Players.LocalPlayer.Character.Humanoid:UnequipTools()
end
lastnum = 3
--if equip[lastnum] == true then
--script.Parent:FindFirstChild(lastnum).BackgroundColor3 = Color3.fromRGB(24, 225, 255)
--else
--script.Parent:FindFirstChild(lastnum).BackgroundColor3 = Color3.fromRGB(104,104,104)
--end
--print(equip[lastnum])
print(equip[3])
print(equip)
end
end)
inputservice.InputBegan:Connect(function(input, gameprocessed)
if input.KeyCode == Enum.KeyCode.Four then
print("e")
script.Parent.invsound:Play()
if equip[lastnum] ~= nil and lastnum ~= 4 then
equip[lastnum] = false
print(equip[lastnum])
end
equip[4] = not equip[4]
if equip[4] == true then
game.Players.LocalPlayer.Character.Humanoid:EquipTool(script.Parent["4"].obj.Value)
else
game.Players.LocalPlayer.Character.Humanoid:UnequipTools()
end
lastnum = 4
--if equip[lastnum] == true then
--script.Parent:FindFirstChild(lastnum).BackgroundColor3 = Color3.fromRGB(24, 225, 255)
--else
--script.Parent:FindFirstChild(lastnum).BackgroundColor3 = Color3.fromRGB(104,104,104)
--end
--print(equip[lastnum])
print(equip[4])
print(equip)
end
end)
inputservice.InputBegan:Connect(function(input, gameprocessed)
if input.KeyCode == Enum.KeyCode.Five then
print("e")
script.Parent.invsound:Play()
if equip[lastnum] ~= nil and lastnum ~= 5 then
equip[lastnum] = false
print(equip[lastnum])
end
equip[5] = not equip[5]
if equip[5] == true then
game.Players.LocalPlayer.Character.Humanoid:EquipTool(script.Parent["5"].obj.Value)
else
game.Players.LocalPlayer.Character.Humanoid:UnequipTools()
end
lastnum = 5
--if equip[lastnum] == true then
--script.Parent:FindFirstChild(lastnum).BackgroundColor3 = Color3.fromRGB(24, 225, 255)
--else
--script.Parent:FindFirstChild(lastnum).BackgroundColor3 = Color3.fromRGB(104,104,104)
--end
--print(equip[lastnum])
print(equip[5])
print(equip)
end
end)
inputservice.InputBegan:Connect(function(input, gameprocessed)
if input.KeyCode == Enum.KeyCode.Six then
print("e")
script.Parent.invsound:Play()
if equip[lastnum] ~= nil and lastnum ~= 6 then
equip[lastnum] = false
print(equip[lastnum])
end
equip[6] = not equip[6]
if equip[6] == true then
game.Players.LocalPlayer.Character.Humanoid:EquipTool(script.Parent["6"].obj.Value)
else
game.Players.LocalPlayer.Character.Humanoid:UnequipTools()
end
lastnum = 6
--if equip[lastnum] == true then
--script.Parent:FindFirstChild(lastnum).BackgroundColor3 = Color3.fromRGB(24, 225, 255)
--else
--script.Parent:FindFirstChild(lastnum).BackgroundColor3 = Color3.fromRGB(104,104,104)
--end
--print(equip[lastnum])
print(equip[6])
print(equip)
end
end)
script.Parent["1"].TextButton.MouseButton1Down:Connect(function()
print("e")
script.Parent.invsound:Play()
if equip[lastnum] ~= nil and lastnum ~= 1 then
equip[lastnum] = false
print(equip[lastnum])
end
equip[1] = not equip[1]
if equip[1] == true then
game.Players.LocalPlayer.Character.Humanoid:EquipTool(script.Parent["1"].obj.Value)
else
game.Players.LocalPlayer.Character.Humanoid:UnequipTools()
end
lastnum = 1
print(equip[1])
print(equip)
end)
script.Parent["2"].TextButton.MouseButton1Down:Connect(function()
print("e")
script.Parent.invsound:Play()
if equip[lastnum] ~= nil and lastnum ~= 2 then
equip[lastnum] = false
print(equip[lastnum])
end
equip[2] = not equip[2]
if equip[2] == true then
game.Players.LocalPlayer.Character.Humanoid:EquipTool(script.Parent["2"].obj.Value)
else
game.Players.LocalPlayer.Character.Humanoid:UnequipTools()
end
lastnum = 2
print(equip[2])
print(equip)
end)
script.Parent["3"].TextButton.MouseButton1Down:Connect(function()
print("e")
script.Parent.invsound:Play()
if equip[lastnum] ~= nil and lastnum ~= 3 then
equip[lastnum] = false
print(equip[lastnum])
end
equip[3] = not equip[3]
if equip[3] == true then
game.Players.LocalPlayer.Character.Humanoid:EquipTool(script.Parent["3"].obj.Value)
else
game.Players.LocalPlayer.Character.Humanoid:UnequipTools()
end
lastnum = 3
print(equip[3])
print(equip)
end)
script.Parent["4"].TextButton.MouseButton1Down:Connect(function()
print("e")
script.Parent.invsound:Play()
if equip[lastnum] ~= nil and lastnum ~= 4 then
equip[lastnum] = false
print(equip[lastnum])
end
equip[4] = not equip[4]
if equip[4] == true then
game.Players.LocalPlayer.Character.Humanoid:EquipTool(script.Parent["4"].obj.Value)
else
game.Players.LocalPlayer.Character.Humanoid:UnequipTools()
end
lastnum = 4
print(equip[4])
print(equip)
end)
script.Parent["5"].TextButton.MouseButton1Down:Connect(function()
print("e")
script.Parent.invsound:Play()
if equip[lastnum] ~= nil and lastnum ~= 5 then
equip[lastnum] = false
print(equip[lastnum])
end
equip[5] = not equip[5]
if equip[5] == true then
game.Players.LocalPlayer.Character.Humanoid:EquipTool(script.Parent["5"].obj.Value)
else
game.Players.LocalPlayer.Character.Humanoid:UnequipTools()
end
lastnum = 5
print(equip[5])
print(equip)
end)
script.Parent["6"].TextButton.MouseButton1Down:Connect(function()
print("e")
script.Parent.invsound:Play()
if equip[lastnum] ~= nil and lastnum ~= 6 then
equip[lastnum] = false
print(equip[lastnum])
end
equip[6] = not equip[6]
if equip[6] == true then
game.Players.LocalPlayer.Character.Humanoid:EquipTool(script.Parent["6"].obj.Value)
else
game.Players.LocalPlayer.Character.Humanoid:UnequipTools()
end
lastnum = 6
print(equip[6])
print(equip)
end)
function refreshgui()
for i, v in pairs(game.Players.LocalPlayer.Backpack:GetChildren()) do
script.Parent:FindFirstChild(i).TextLabel.Text = v.Name
script.Parent:FindFirstChild(i).obj.Value = v
end
end
while wait() do
refreshgui()
for i, v in pairs(game.Players.LocalPlayer.Backpack:GetChildren()) do
if equip[1] == true then
script.Parent:FindFirstChild("1").BackgroundColor3 = Color3.fromRGB(24, 225, 255)
else
script.Parent:FindFirstChild("1").BackgroundColor3 = Color3.fromRGB(104,104,104)
end
if equip[2] == true then
script.Parent:FindFirstChild("2").BackgroundColor3 = Color3.fromRGB(24, 225, 255)
else
script.Parent:FindFirstChild("2").BackgroundColor3 = Color3.fromRGB(104,104,104)
end
if equip[3] == true then
script.Parent:FindFirstChild("3").BackgroundColor3 = Color3.fromRGB(24, 225, 255)
else
script.Parent:FindFirstChild("3").BackgroundColor3 = Color3.fromRGB(104,104,104)
end
if equip[4] == true then
script.Parent:FindFirstChild("4").BackgroundColor3 = Color3.fromRGB(24, 225, 255)
else
script.Parent:FindFirstChild("4").BackgroundColor3 = Color3.fromRGB(104,104,104)
end
if equip[5] == true then
script.Parent:FindFirstChild("5").BackgroundColor3 = Color3.fromRGB(24, 225, 255)
else
script.Parent:FindFirstChild("5").BackgroundColor3 = Color3.fromRGB(104,104,104)
end
if equip[6] == true then
script.Parent:FindFirstChild("6").BackgroundColor3 = Color3.fromRGB(24, 225, 255)
else
script.Parent:FindFirstChild("6").BackgroundColor3 = Color3.fromRGB(104,104,104)
end
end
end
Video of the issue:
Edit:Issue fixed