Lay models out in a line

So i’ve been trying to lay out a folder of models in a line with the command bar, here’s what I have rn

local mans = game.Workspace.SecretChars:GetChildren()
local lastpos = nil
for i, v in pairs(mans) do
	if lastpos ~= nil then
		v:SetPrimaryPartCFrame(CFrame.new(v.PrimaryPart.Position) + Vector3.new(5, 0, 0))
		lastpos = v
	end
	v:SetPrimaryPartCFrame(CFrame.new(183.269, 3, 68.588) + Vector3.new(5, 0, 0))
	lastpos = v
end

and here’s the error I got
image

Maybe the models aren’t loaded yet, try adding wait() or WaitForChild().

Strange. :GetChildren() should never return nil.

Check the spelling of your variables. Maybe you’ve typed something wrong?

1 Like

Although this isnt what you’re asking for, you can change your code to this:

local mans = workspace.SecretChars:GetChildren()
local xfive = Vector3.xAxis*5 -- equivilent to Vector3.new(5,0,0)
local lastPos -- doesnt require nil


for i, v in pairs(mans) do
	if lastPos then -- if lastPos isnt nil
		v:PivotTo(CFrame.new(v.PrimaryPart.Position + xfive)) -- SetPrimaryPartCFrame is deprecated, so you should be using PivotTo
		lastpos = v
	end
	v:PivotTo(CFrame.new(183.269, 3, 68.588) * CFrame.new(xfive)) -- may not be correct
	lastpos = v
end
1 Like

when executing this, they’re all just in the same position, keep in mind i’m executing this with the command bar not in testing, but in studio itself
image

You need to use the lastpos above to get them to not go in the same spot:

my brain isnt working can you elaborate

I fixed the code you had. In your code you had this line:

v:SetPrimaryPartCFrame(CFrame.new(v.PrimaryPart.Position) + Vector3.new(5, 0, 0))

You aren’t referencing the previous character so the position would just keep putting them all in the same place. I changed the “v.PrimaryPart.Position” to be “lastpos.PrimaryPart.Position” so that it will shift from the previous character over instead of putting them all in the same spot. You should just need to replace your code lines with what I gave you.