Converting list index contents into vector3 values

So I’m trying to position a part relative to a a list where the index is from a do loop (the code explains this better).

However, I’m unable to convert the list contents into vector3 values.

I’m trying to avoid if statements so I’ve decided to go this route. I converted the list index contents into a integer, but I get an error I think due to the commas. I reckon I need to add the commas using some string formatting.

Code:

local Positions = {
	[1] = "0, 0, 10", 
	[2] = "0, 0, 0",
	[3] = "0, 0, -10",
	[4] = "10,0,-10"
}

for i, v in pairs(folder:GetChildren()) do
	part.Cframe = CFrame.new(tonumber(Positions[i]))
end

Any guidance will be greatly appreciated.

I’m now getting a invalid argument #1 to ‘new’ (Vector3 expected, got number) error, I also printed the value of tonumber(_i) which is equal to 4 apparently not 0,0,0 which its meant to be.

Try this then?
local Positions = {
	[1] = "0, 0, 10", 
	[2] = "0, 0, 0",
	[3] = "0, 0, -10",
	[4] = "10,0,-10"
}

for i, v in pairs(folder:GetChildren()) do
	for _i, _ in pairs(Positions) do
		part.Cframe = CFrame.new(Vector3.new(tonumber(_i)))
	end
end

might not work but it also might work, cause roblox is like that

Okay, now I’m getting a invalid argument #1 to ‘new’ (Vector3 expected, got CFrame) with an output of 4, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1 lol.

what the heck roblox :frowning:

game.Workspace.Part.CFrame = CFrame.new(Vector3.new("10,10,10"))

this seemed to work, so try this:

local Positions = {
	[1] = "0, 0, 10", 
	[2] = "0, 0, 0",
	[3] = "0, 0, -10",
	[4] = "10,0,-10"
}

for i, v in pairs(folder:GetChildren()) do
	for _i, _ in pairs(Positions) do
		part.CFrame = CFrame.new(Vector3.new(_i))
	end
end

Try this:

local Positions = {
	[1] = "0, 0, 10", 
	[2] = "0, 0, 0",
	[3] = "0, 0, -10",
	[4] = "10,0,-10"
}

for i, v in pairs(folder:GetChildren()) do
        local str = Positions[i]
        local vecXYZ= str:split(",")
        v.CFrame = CFrame.new(tonumber(vecXYZ[1]), tonumber(vecXYZ[2]), tonumber(vecXYZ[3]))
end

(Edit: added tonumber)

1 Like

Legend. Part’s Cframe changes accordingly.