Inventory limit not working

I’m trying to make a inventory system with limits. But after all the items in the inventory have been removed simultaneously, it won’t let me collect stuff anymore. It’s saying that its over the inventory limit.

Only important code:

if #plr.Inventory:GetChildren() + #script.Parent.Parent.Contains:GetChildren() >= plr.Stats.InvSize.Value then
--warn player for inv limit.

can we see the rest of the script? because i dont understand why u adding something to it

ive also noticed youre not even comparing the result of these additions into a max limit, like

local Limit = 30
if #plr.Inventory:GetChildren() + #script.Parent.Parent.Contains:GetChildren() >= Limit then
--warn player for inv limit.
end

Oh i didn’t copt the comparison over. My bad!

I’m adding because the collected things could give 2 items. If i give 2 items and it doesn’t check for the limit then it will go over it.

it means the children of script.Parent.Parent.Contains doesnt get cleared or the plr.Inventory doesnt
thats why its still going over the limit

u need to show us the whole script that is involved in this subject

Found the problem. The sell menu destroys the inventory things LOCALLY. Meaning the script never knows when they are gone.
Thanks for your patience.