Hi, I'm a bit rusty at scripting at the moment and I'm trying to make a closest part script.The problem is that it selects all the parts and not the closest one. Here's the script:
while wait() do
for i,v in pairs(workspace:GetChildren()) do
if v ~= script.Parent and v ~= workspace.Baseplate and v.ClassName == script.Parent.ClassName then
local mag = (script.Parent.Position - v.Position).magnitude
if mag <= 50 then
print(v.Name)
end
end
end
end
Any help is appreciated

3 comments
https://scriptinghelpers.org/questions/43278/my-script-that-judges-distance-of-blocks-in-a-group-and-the-closest-one-is-printed-is-not-working#44696
Sorry but how could I apply that to my script, i can't think straight and see what my scripts problem is
It is explained in the answer how the function works but you would pass it the workspace and the script.Parent.Position. It will then return the closest part and the magnitude of the position.