function funcNear() local nearestPlr for _, val in pairs(game.Players:GetPlayers()) do local char = val.Character if char then local dist = val:DistanceFromCharacter(script.Parent.HumanoidRootPart.Position) if dist < script.Parent.Configuration.TriggerDistance.Value then local nearestPlr = char print(nearestPlr) end end end return nearestPlr end while wait(3) do local x = funcNear() print(x) end
nearestPlr is just returning nil when being called.
have you realized you created nearestPlr twice?
once in line 2, local nearestPlr
twice in line 8, local nearestPlr = char
that is two different variables!!!!
by the time it reach line 13, the second variable is out of scope, it is returning the value in first variable created in line 2. oops. you have never set that variable in the first place.
just remove "local " in line 8