local function GetClosestShop()
local Distance = 6
local Closest = nil
for Index,Shop in pairs(ShopData) do
local newDistance = LocalPlayer:DistanceFromCharacter(FunctionParts[Index].Position)
if newDistance <= Distance then
Closest = Shop
end
end
return Closest
end
I think I should use math.min.
Is that possible?
I took me some time to make this one but I’m happy to make it smaller.
Nah, this seems pretty solid. You’re going to need to loop through FunctionParts eventually, so you might as well check their distances while you’re iterating!
Also, math.min doesn’t give you an index, so you’d only be able to get the minimum distance from it, not the shop itself.