X is not a valid member of part

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I am trying to find the closest part to a position

  2. What is the issue?
    I am getting an error that says

x is not a valid member of part.

  1. What solutions have you tried so far?
    I’ve gone through my code and have found where the error is but it looks like it is find.
Module
local function FindDistenceBetweenLocations (vec1,vec2)
	-- values
	local x1, y1, z1 = vec1.x, vec1.y, vec1.z
	local x2, y2, z2 = vec2.x, vec2.y, vec2.z
	
	--Minises
	local x, y, z = x2 - x1, y1 - y2, z1 - x2
	
	--squared
	local x, y, z = math.pow(x,2), math.pow(y,2), math.pow(z,2)
	
	--added
	local added = x + y + z
	
	--squareRoot
	
	local sqrt = math.sqrt(added)
	
	return sqrt
end




local part1 = workspace.Part.Position

return function (group, pos)
	local closestPart
	local closestPartDistence
	local maxDistence = 20
	closestPart = group[1]
	closestPartDistence = FindDistenceBetweenLocations(pos, closestPart.Position)
	for i=2, #group do 
		if FindDistenceBetweenLocations(group[i],pos) > closestPartDistence then
			print("---")
			local closestPart = group[i]
			local closestPartDistence = FindDistenceBetweenLocations(group[i].Position,pos) -- I'm pretty sure the error is here.
			
		end
	end
	return {closestPart,closestPartDistence}
end
Script
local parts = {game.Workspace.Part, game.Workspace.Part1, game.Workspace.Part2}

local Distence_Func = require(game.ReplicatedStorage.modules.FindClosestPartInArray)


print(Distence_Func(parts, Vector3.new(0,0,0)).closestPart.Name)

Thanks for helping.

1 Like

Can I see the FindClosestPartInArray function?

1 Like

That function is the one at the bottom of the module

1 Like

I believe it’s because you are passing the part here, not its vector. Try adding .Position at the end of group[i].

2 Likes

You missed the .Position on group[i]

@starmaq Vectors do accept lowercase components

3 Likes

Thanks a lot.

WHY THIRTY CHARACTERS