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
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.