Is there a better way to store these CFrame values

I am currently making a nod generation script.
I stored the Position of every location I want a nod to spawn at.
I want to generate like 200 nods, so I need 200 different locations.

IS THERE A BETTER WAY TO STORE THEM? AND WILL 200 ITEMS IN A TABLE GREATLY AFFECT THE GAME PERFOMANCE?

local NodPositionTable = {}
NodPositionTable[1] = CFrame.new(21.8, 12.051, -198.328)
NodPositionTable[2] = CFrame.new(21.8, 12.051, -206.028)
NodPositionTable[3] = CFrame.new(21.8, 12.051, -214.028)
NodPositionTable[4] = CFrame.new(21.8, 12.051, -221.928)
NodPositionTable[5] = CFrame.new(59.6, 12.051, -173.028)
NodPositionTable[6] = CFrame.new(79.1, 12.051, -193.528)
NodPositionTable[7] = CFrame.new(50.9, 12.051, -215.928)

I only chose 7 locations for now and I see that the block of code is getting kinda big, so I wanted to know if there was a better way to store them.

1 Like

Not at all.

First off, you don’t have to [] each individual thing into the table.

local NodPositionTable = {
	-- 1..5
	CFrame.new(21.8, 12.051, -198.328),
	CFrame.new(21.8, 12.051, -206.028),
	CFrame.new(21.8, 12.051, -214.028),
	CFrame.new(21.8, 12.051, -221.928),
	CFrame.new(59.6, 12.051, -173.028),
	-- 6..7
	CFrame.new(79.1, 12.051, -193.528),
	CFrame.new(50.9, 12.051, -215.928),
}

You could also replace all of the CFrames with Vector3 to save some memory because you don’t seem to be using any rotation, only positions.

I would heartily suggest not using a table, though. Since they seem to be points in the world, you should rather place parts at all of the nodes’ positions.

If the order of the nodes does not matter, then you can just :GetChildren() the model or folder containing them.
edit: then turn them into positions

local NodPositionTable = model:GetChildren()
for i,v in ipairs(NodPositionTable) do
NodPositionTable[i] = v.Position
end

If the order does matter, then the effort of maintaining an order via name or attachment or something becomes larger than just sticking an extra CFrame in a table in some script, though :frowning:

1 Like