I have tried to get all the parts and have the variable for the count incrémented but it does not work, i have no code to show at the moment
This is easy with using for blank,blank in pairs do
.
for i,v in pairs(game:GetDescendants()) do wait(.1) if v:IsA("Part") then print("Parts") -- this will add up a number next to the print in the console (Parts(xnumberofparts) end
I edited my question so it will not print infinitely.
Get the script to loop it through the parts and add up a value each time it is a base part
local CountedBricks = 0 --Variable to count how many bricks. for _, v in pairs(game:GetDescendants) do --Every thing in the game if v:IsA("BasePart") then -- If it is a part CountedBricks = CountedBricks + 1 --If it's a part it will add 1 to the variable. end end print(CountedBricks) --------- Function --------- function CountBricks() local CountedBricks = 0 --Variable to count how many bricks. for _, v in pairs(game:GetDescendants) do --Every thing in the game if v:IsA("BasePart") then -- If it is a part CountedBricks = CountedBricks + 1 --If it's a part it will add 1 to the variable. end end return(CountedBricks) end
How would you use the fucntion?
for instance you could do :
print(tostring(CountBricks()))