Module script can't find the primary part

so im having a problem, the script cant find the primary part of a model, but there is.
for some reason this function and some other lines error that there isnt a primary part, but i checked there is. i have another script which also checks for a primary part (normal scipt) and it works fine, but this module script not really
image

	local function findClosestPart(group, position)
		if #group == 0 then
			return nil, nil
		end

		local closestPart, closestPartMagnitude

		for _, part in group do
			local tmpMagnitude = (position - part.PrimaryPart.Position).magnitude

			if not closestPart or tmpMagnitude < closestPartMagnitude then
				closestPart = part.PrimaryPart
				closestPartMagnitude = tmpMagnitude
			end
		end

		return closestPart, closestPartMagnitude
	end

the error is “attempt to index nil with ‘Position’”

if needed i can send the whole script.

1 Like

Are you sure the PrimaryPart is not a model?

1 Like

The primary part was not anchored :sob:
sorry didn’t check that

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.