Hello, i am trying to do an script that prevents more than 20 parts or objects being added to a character, but ChildAdded does not work, it gives no errors, Can i get some help please, i tried to move it but nothing, and the for i,v in pairs does work. :/.
local Chara = plr.Character
local Total = 0
Chara.ChildAdded:Connect(function(a)
print("CHILD ADDED")
print("and child's name is "..a.Name)
end)
for i,v in pairs(Chara:GetChildren()) do
if not v:IsA("Accessory") and not v:IsA("Pants") and not v:IsA("BodyColors") and not v:IsA("ForceField") and not v:IsA("Shirt") then
print(v.ClassName)
print("can go")
Total = Total+1
end
end

2 comments
Just add a check that sees if the total is greater than or equal to 20, and, if so, it destroys the new child (which, in your case, would be a).
Might be a good idea to have a running total instead of looping every single time a child is added to the character.