How to send to a function which axis to check?

Unimportant.

“Body too similar to what you recently posted” because I accidentally posted this in another category. What do you expect me to do now?

Hello! I’m to store all X,Y and Z axis positions of multiple parts in separate tables. To do this neatly, I was thinking about calling the same function 3 times while telling the function which axis to extract. Not sure on how to do it, though. This is what I came up with and… it doesn’t work. Not that surprised.

local function sortPartPositions(Parts, typeOfCoord)
	local PartPositions = {}
	for _,v in pairs(Parts) do
		table.insert(PartPositions, v.Position.typeOfCoord)
	end

	return PartPositions
end

local Xtable, Ytable, Ztable = sortPartPositions(Parts, X), sortPartPositions(Parts, Y), sortPartPositions(Parts, Z)

Error is
typeOfCoord is not a valid member of Vector3

Any help? Thanks in advance!

Try this:

local function CheckAxis(Part, Axis)
	local AxisTable = {}

	for _, v in pairs(game:GetService("Workspace"):GetChildren()) do
		if v:IsA(Part) then
			table.insert(AxisTable, v.Position[Axis])
		end
	end

	print(AxisTable) -- To check if the axis is correct!
	return AxisTable

end

CheckAxis("Part", "Y") 

That should print Y axis of a part in workspace, for instance the y axis of a baseplate.

1 Like