Problem with list, should I use a 3d array?

Do I need to make this a 3d array?
It is not cycling through all of the objects

error:

Workspace.Bait.Spawn1.Robot.Script:37: attempt to index nil with 'className'

This script is supposed to cycle through all the children and pick out the right objects. Why is not all the children being sorted through?

local list = {
		game.Workspace.ZednovTycoonKit.Tycoons.Castle2.PurchasedObjects:GetChildren() ,
		game.Workspace.ZednovTycoonKit.Tycoons.Castle4.PurchasedObjects:GetChildren() ,
		game.Workspace.ZednovTycoonKit.Tycoons.Castle3.PurchasedObjects:GetChildren() ,
		game.Workspace.ZednovTycoonKit.Tycoons.Castle1.PurchasedObjects:GetChildren()
		}
	local temp2 = nil
	for x = 1, #list do
		if (list[x].Name == "Spawn1") then
			temp2 = list[x].Robot
		end
		if (list[x].Name == "Spawn2") then
			temp2 = list[x].Bull
		end
		if (list[x].Name == "Spawn3") then
			temp2 = list[x].EvilGiant
		end
		if (list[x].Name == "Spawn6") then
			temp2 = list[x]
		end
		if (list[x].Name == "Walls1") then
			temp2 = list[x]
		end
		if (list[x].Name == "OwnerOnlyDoor") then
			temp2 = list[x]
		end
if (temp2.className == "Model") and (temp2 ~= script.Parent) then

other section of the script is not necessary

You should try using CollectionService to tag the spawns as “Spawn”, as it is a more optimized method of getting specific parts.

2 Likes

I believe that task.spawn() is a new method of calling multiple functions at once and yields faster than coroutines.

1 Like

Yeah I keep forgetting about task, but you were saying to use CollectionService to tag each item as “spawn”, I thought you said use Spawn (the function) lol

1 Like