Tip For The Future: You Need Not Capitalize Every Word Like This, Which Is In Fact Wrong To Do.
That aside, let's help you through the script, because you've clearly put effort to it before presenting it. Before you ask, that's a good thing.
Along with the character you will need to wait for the player too, unless you manually (via another script) give the script to the player.
To get the amount of items in a table, you can use # and cut yourself a variable (in this case, "amount"). For instance, #player.Backpack:GetChildren() will get the amount of items the player is carrying, supposing player is game.Players.LocalPlayer.
In cases where you are connecting to an event where a child/player is removed, it's ChildRemoving and PlayerRemoving accordingly. Instances don't exactly remove the instant they are called to, so the Roblox devs decided to name the event as such.
When you set a variable, the value doesn't update unless you set it again. So you'd have to set inventory every time it was required to get the accurate table of items.
I left the character variable in just in case you'll use it later.
repeat wait() until game.Players.LocalPlayer
local player = game.Players.LocalPlayer
repeat wait() until player.Character
local character = player.Character
player.Backpack.ChildAdded:connect(function(child)
local amount = #player.Backpack:GetChildren()
if child:IsA("Tool") then
if amount == 11 then
wait(.1)
child:Destroy()
end
end
end)
player.Backpack.ChildRemoving:connect(function(removed)
local amount = #player.Backpack:GetChildren()
if removed:IsA("Tool") and amount > 10 then
print(amount)
end
end)
1 comment
Well, you haven't exactly told us what was wrong with it, but on line 16, flip that > and make it a <. Any other errors?