I can't find a way to constantly check the player's backpack for a new item that has been added such as when the player picks up a new tool. I tried using ChildAdded and ChildRemoved but those events activate every time an item gets added to the backpack which is a problem since when a player equips a tool, it gets added to the character model but when they equip it, it goes back to the backpack which then fires the event.
local player = game.Players.LocalPlayer
local char = player.Character
local myHum = char:WaitForChild('Humanoid')
local backPack = player:WaitForChild('Backpack')
local space = script.Space
local mainFrame = script.Parent:WaitForChild('MainFrame')
local selectedItem = script.Parent.SelectedItem
local inventory = {}
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false) -- disable default backpack Gui
--//Search
function search(location)
for i,v in pairs(location:GetChildren()) do
if v:IsA('Tool') then
table.insert(inventory,v)
end
end
end
--//Add all current items in backpack to inventory
search(backPack)
search(char)
for i,v in pairs(inventory) do
local clone = space:Clone()
clone.Name = v.Name
clone.LayoutOrder = i
clone.Image = v.TextureId
clone.Parent = mainFrame
--//Activated
clone.Activated:Connect(function()
selectedItem.Value = v
if v.Parent == backPack then
myHum:EquipTool(v)
else
myHum:UnequipTools()
end
end)
end
--//Create Button
function create()
backPack.ChildAdded:Connect(function(child)
if child:IsA('Tool') then
local clone = space:Clone()
clone.Name = child.Name
clone.Image = child.TextureId
clone.Parent = mainFrame
end
end)
char.ChildAdded:Connect(function(child)
if child:IsA('Tool') then
local clone = space:Clone()
clone.Name = child.Name
clone.Image = child.TextureId
clone.Parent = mainFrame
end
end)
end
--//Constantly check for changes
while wait() do
search(backPack)
search(char)
create()
end

5 comments
Sorry for the terrible code block, first time using this site in a while so i'm new to the changes.
what about using #backpack:GetChidren()?
change if that is changed and if so something added
You probably want to use ChildAdded, just keep track of what's new or not.
I did but that's not enough since the tool's parent switches from the character model to the backpack depending on whether it's equipped or not.