I tried making a custom hotbar with a video I found online, working in the video, but I added modifications to it to work with my game, which completely broke it.
Local Script is stored in “PlayerStarterScripts”
local tools = player.Backpack:GetChildren()
local slotMax = 9
local numToWord = {
[1] = "One",
[2] = "Two",
[3] = "Three",
[4] = "Four",
[5] = "Five",
[6] = "Six",
[7] = "Seven",
[8] = "Eight",
[9] = "Nine"
}
local function updateHotbar()
for _, child in ipairs(hotbar:GetChildren()) do
if child:IsA("Frame") and child.Name == "Slot" then
child:Destroy()
end
end
for i, tool in ipairs(tools) do
if i > slotMax then break end
if tool and tool:IsA("Tool") then
local slotCreated = false
for _, Folder in pairs(ReplicatedStorage.Weapons:GetChildren()) do
for _, SubFolder in pairs(Folder:GetChildren()) do
if ffc(SubFolder, tool.Name) and ffc(tool,"ACS_Settings") then
local Weapon = wfc(SubFolder, tool.Name)
local WeaponType = require(Weapon.ACS_Settings).WeaponType
local Clone = TemplateW:Clone()
Clone.Name = "Slot"
Clone.ToolName.Text = tool.Name
Clone.Visible = true
Clone.HotkeyNumber.Text = i
Clone.Parent = hotbar
Clone.Image.ImageLabel.Image = Temp(player.Character)
slotCreated = true
break
end
end
if slotCreated then break end
end
if not slotCreated then
local Clone = TemplateT:Clone()
Clone.Name = "Slot"
Clone.ToolName.Text = tool.Name
Clone.Visible = true
Clone.HotkeyNumber.Text = i
Clone.Parent = hotbar
end
UserInputService.InputBegan:Connect(function(input, processed)
if not processed then
if input.KeyCode == Enum.KeyCode[numToWord[i]] then
ForceEquipToolRE:FireServer(tool, tool.Parent)
end
end
end)
else
print("Invalid tool at index " .. i)
end
end
end
player.CharacterAdded:Connect(function(character)
--[[HOTBAR]]
player.Backpack.ChildAdded:Connect(function(child)
if not table.find(tools, child) then
table.insert(tools, child)
updateHotbar()
end
end)
player.Backpack.ChildRemoved:Connect(function(child)
if player.Character and child.Parent ~= character then
table.remove(tools, tools[child])
updateHotbar()
end
end)
character.ChildAdded:Connect(function(child)
if child:IsA("Tool") and not table.find(tools, child) then
table.insert(tools, child)
updateHotbar()
end
end)
character.ChildRemoved:Connect(function(child)
if child.Parent ~= player.Backpack then
table.remove(tools, tools[child])
updateHotbar()
end
end)
ForceEquipToolRE.OnClientEvent:Connect(function()
for _, slot in pairs(hotbar:GetChildren()) do
if slot:IsA("Frame") and (slot~=TemplateT or slot~=TemplateW) then
local tool = tools[tonumber(slot.HotkeyNumber.Text)]
if tool.Parent ~= player.Character then
slot.UIStroke.Enabled=false
else
slot.UIStroke.Enabled=true
end
end
end
end)
end)
Stuff that isn’t working:
- Not all tools in the player backpack being shown in the Hotbar
- Keybinds are also completely broken, equipping the wrong tools
- Equipping tools lags extremly
Showcase of the problem