- What I want to achieve?
I want to get the part that is closest to the point object in a folder of other parts
- What is the issue?
the issue is that I’ve never used table.sort or anything remotely close to this so I don’t know how too.
local Workspace = game:GetService("Workspace")
local Point = Workspace:FindFirstChild("Point")
local AllParts = Workspace.Folder:GetChildren()
function returnRange(obj1, obj2)
return (obj1.Position - obj2.Position).Magnitude
end
table.sort(AllParts, returnRange(Point,AllParts[1]) <= returnRange(AllParts[1], Point))
for i, v in pairs(AllParts) do
print(v)
end