My Hotbar wont updating when I remove tool from backpack .I can’t find any problems that similar to my problem. This is the script:
game:GetService('StarterGui'):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
local plr = game.Players.LocalPlayer
local char = plr.Character
local backpack = plr:WaitForChild("Backpack")
local tools = backpack:GetChildren()
local slotMax = 9
local hotbar = script.Parent
local numToWord =
{
[1] = "One",
[2] = "Two",
[3] = "Three",
[4] = "Four",
[5] = "Five"
}
local function updateHotbar()
for i, child in pairs(hotbar:GetChildren()) do
if child.Name == "ImageButton" then child:Destroy() end
end
for i, tool in pairs(tools) do
if i > slotMax then return end
local slotClone = script.ImageButton:Clone()
slotClone.HotkeyNumber.Text = i
slotClone.Image = tool.TextureId
slotClone.ItemName.Value = tool.Name
slotClone.Parent = hotbar
if tool.Parent == char then
slotClone.BackgroundColor3 = Color3.fromRGB(255,255,255)
end
game:GetService("UserInputService").InputBegan:Connect(function(input, processed)
if not processed then
if input.KeyCode == Enum.KeyCode[numToWord[i]] then
game.ReplicatedStorage.EquipToolRE:FireServer(tool, tool.Parent)
end
end
end)
slotClone.MouseButton1Click:Connect(function()
game.ReplicatedStorage.EquipToolRE:FireServer(tool , tool.Parent)
end)
end
end
updateHotbar()
backpack.ChildAdded:Connect(function(child)
if not table.find(tools, child) then
table.insert(tools, child)
updateHotbar()
end
end)
backpack.ChildRemoved:Connect(function(child)
if child.Parent ~= char then
table.remove(tools, tools[child])
updateHotbar()
end
end)
char.ChildAdded:Connect(function(child)
if child:IsA("Tool") and not table.find(tools, child) then
table.insert(tools, child)
updateHotbar()
end
end)
char.ChildRemoved:Connect(function(child)
if child.Parent ~= backpack then
table.remove(tools, tools[child])
updateHotbar()
end
end)
any help is appreciated . Also can anyone tell me how to upload vid without you guys downloading it . Thanks