Hey, the name’s Pumpy, also known as Pumpstormz. I need feedback on this, ‘ClosestObject,’ ModuleScript I’m working on. I’m unable to test it, because I don’t have my PC available at the moment, so if you could help I’d really appreciate it.
Here’s the ModuleScript:
local module = {}
function module:ClosestObj(obj, root)
while wait() do
local closestObj
local maxDistance = math.huge
if not closestObj then
for i, v in pairs(workspace:GetDescendants()) do
if v.Name == obj then
local goal = v
local magnitude = (root.Position - goal.Position).magnitude
if magnitude < maxDistance then
closestObj = goal
print(closestObj)
end
end
end
end
end
end
return module
Basically when I call the function, I would put the name of the object as a string for the first perimeter, and for the second I would put Character’s HumanoidRootPart. Let me know if I did anything wrong.