Spawnlocation is considered 'Part' Class(?)

image
So we have 9 items inside this folder and i want to count how many parts inside the folder so its 5 parts but ill use a for loop to count how many ‘part(s)’ are inside the folder

local count = 0
for i,v in pairs(workspace.Folder:GetChildren()) do
 if v:IsA("Part") then count+=1 end 
end
print(count,"parts are inside this folder")

Output =


so this means that its also acknowledging the SpawnLocations are also ‘Parts’
but if you change the IsA to v.ClassName == “Part” it will count 5 parts inside the folder but isnt IsA a function that returns what Class an item is? and why is the spawnlocations considered ‘Parts’?

:IsA() function not only checks object’s ClassName property , it also checks it’s superclasses and Spawnlocation is an object that inherits from Part class so :IsA() function counts it as a part.

You can prevent that from happening by adding another statement to the if statement

for i,v in pairs(workspace.Folder:GetChildren()) do
 if v:IsA("Part") and not v:IsA("SpawnLocation") then count+=1 end 
end
1 Like