local function ReturnNearestGoal()
local Root = plr.Character.HumanoidRootPart
local Goal
for i, v in pairs(workspace:GetChildren()) do
local NGoal = v:findFirstChild("Goal", true)
if NGoal and (NGoal.Position - Root.Position).magnitude > 25 and (NGoal.Position - Root.Position).magnitude < 70 then
Goal = NGoal
break
elseif NGoal and (NGoal.Position - Root.Position).magnitude > 70 then
Goal = nil
break
end
end
return Goal, Root
end
I'm trying to use this local function for identifying the nearest Goal in the workspace. It works, but It doesn't identify any other goals. I have 2 goals in the game. Any help?
It's used like this
local Goal, Root = ReturnNearestGoal()