****I solved this issue myself, no help is needed****
I was making a script that limits the amount of items a player can have in their backpack, and I was going to do this by force dropping whatever item they just picked up if they have the max number of items in their inventory. However, I don't know how to force drop an item that the player just picked up.
My script looks like this:
limit = 2 game.Players.PlayerAdded:Connect(function(p) p.Backpack.ChildAdded:Connect(function(tool) local items = p.Backpack:GetChildren() if #items == limit then -- force drop item end end) end)
Any help is appreciated!
You can't necessarily "force" a player to drop an item. You would have to destroy it. Try this out:
limit = 2 game.Players.PlayerAdded:Connect(function(p) p.Backpack.ChildAdded:Connect(function(tool) local items = p.Backpack:GetChildren() if #items > limit then -- greater than 2 (you can also put >= which is greater than or equal to) tool:Destroy() end end) end)