I tried to make a Backpack limit so people can have a weapon limit in my rpg game, and I can not figure it out, could somebody help or type in the code?
Here is a example code, but this free model did not work
limit = 8 -- amount of items a player can carry
game.Players.PlayerAdded:Connect(function(p)
wait(1)
p.Character.ChildAdded:Connect(function(tool)
local items = p.Backpack:GetChildren()
local charitems = p.Character:FindFirstChildWhichIsA("Tool")
if #items >= limit then
wait(.5)
tool.Parent = workspace
end
end)
end)
(EDIT) It sends it into the players Backpack When somebody buys a weapon from my shop gui it clones and sends it to the backpack, but even with this script, it still goes through.

2 comments
Does the shop put it in the character or backpack? If the backpack then it should be p.Backpack.ChildAdded:Connect(function()
It's backpack, could you show me the whole code?