Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Finding the nearest Basketball Goal (help?)

Asked by 5 years ago

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()
0
It's probably because they share the same name. Mr_Unlucky 1085 — 5y

Answer this question