Trying to call a function based on the amount of children in a folder

Like the title says I want call a function based on how many objects are in a table inside of serverStorage but its not working and only calling it once


local animalsFolder = game.ServerStorage.animals:GetChildren()
for i = 1, #animalsFolder do

Are you sure it’s only being called once? It seems like there’s an issue with your function.

Put a print statement within the for loop and see how often it prints to the console. I tested it myself and it prints the correct number of times based off of the children in the folder.

Yeah I checked too and it does do it the amount of times it should so I thin k it is a problem with the function but I dont know what the problem is though

local function placeRandomly(obj,pos)
		local newObj = obj:Clone()
		newObj.Parent = workspace
		print("Spawned "..newObj.Name)
		for _, species in pairs(animals) do
			if obj.Name == species.Name then
				local dwiddleAnimal =



It’s pretty simple actually. To check the number of things in a folder you can just add a # number sign before what you are checking like this: #(animal folder here) to check or do whatever.

if #(animal folder) then…do your magic

You want to place each animal once?
do this

for i, animal in pairs(animalsFolder) do
  placeRandomly(animal, ...

It will go through the table one item at a time in some order. You should also set the parent after modifying the item you are inserting so it only has to render once. I would set network owner after that as well.

It was a problem with my oop class :cowboy_hat_face: