So i’m working on a attack system
and i want to detect which child of a folder has the lowest magnitude ( the closest to your player )
here’s the script
for i,E_unit in pairs(game.Workspace.Units:GetChildren()) do
local body2 = E_unit.HumanoidRootPart
local Mag = (body.Position - body2.Position).Magnitude
for others in pairs(game.Workspace.Units:GetChildren()) do
local body3 = E_unit.HumanoidRootPart
local Mag2 = (body.Position - body3.Position).Magnitude
if Mag < Mag2 then
local priority = E_unit.Priority
priority.Value += 1
end
end
end
I know this script is unfinished, it’s just that i’m stuck and don’t know how to approach this