Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Find Closest Part Selecting All Parts?

Asked by
Laxely 3
7 years ago
Edited 7 years ago

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

0
Sorry but how could I apply that to my script, i can't think straight and see what my scripts problem is Laxely 3 — 7y
0
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. User#5423 17 — 7y

Answer this question