I managed to make my own Custom Hotbar System work, Equipping it works solidly. Though, I ran into a problem and whenever I unequip the item, my ChildAdded function keeps detecting the tool resulting in duplicating the information to the other remaining Hotbar Slots.
Can anyone help me out so that it doesn’t do that? Do I have to use a different function instead of ChildAdded?
sorry I’m just so drained atp (any help is appreciated )
-- ClientScript
local PlayerStatusFolder = MainFrame.PlayerStatus_Folder
local PlayerBackpack = L_PLR.Backpack
local InventoryFolder = MainFrame.Inventory_Folder
local L_PLR = game:GetService("Players").LocalPlayer
PlayerBackpack.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
toolManager.BackpackUpdate(InventoryFolder, PlayerBackpack, L_PLR)
end
end)
-- ModuleScript
local slotsToNum = {
["SLOT1"] = {
["SlotNum"] = 1,
["Occupied"] = false,
["Tool"] = ""
};
["SLOT2"] = {
["SlotNum"] = 2,
["Occupied"] = false,
["Tool"] = ""
};
["SLOT3"] = {
["SlotNum"] = 3,
["Occupied"] = false,
["Tool"] = ""
};
}
local maxBackpackLimit = 3
local currentNumItems = 0
function M.BackpackUpdate(hotbar, backpack, plr)
currentNumItems += 1
task.wait(0.1)
for _, item in pairs(backpack:GetChildren()) do
if item:IsA("Tool") then
for _, frame in ipairs(hotbar:GetDescendants()) do
if frame:IsA("Frame") and frame.Name == "SLOT"..currentNumItems then
for _, Button in ipairs(frame:GetDescendants()) do
if Button:IsA("TextButton") then
if maxBackpackLimit == currentNumItems then
warn("Items Exceeded!")
print(currentNumItems)
end
if slotsToNum[tostring(frame.Name)]["SlotNum"] == currentNumItems then
if item.Name == ValueManager.Tools[tostring(item.Name)]["CodeName"] then
Button.Text = ValueManager.Tools[tostring(item.Name)]["ToolName"] -- The Button's Text becomes the Tool's Name
slotsToNum[tostring(frame.Name)]["Tool"] = item.Name -- Stores the Tool here for Reference
slotsToNum[tostring(frame.Name)]["Occupied"] = true -- Sets the Value if the Slot is currently Occupied
print(slotsToNum[tostring(frame.Name)]["Tool"])
break
end
end
end
end
end
end
end
end
end