How to do a player distance range function without a loop

Hello, I would like to know how to make the following function activate with only the player with the rank being close, not with a cycle that activates the function

local RangeTronco = script.Parent
local HealtValueGuiEnabled = script.Parent:WaitForChild("EnabledHealthGui")

local function DistanceToEnabled(hit)
	local Range = script.Parent:WaitForChild("Distance").Value
	local target = nil
	for i, Dis in pairs(workspace:GetChildren()) do
		local Human  = Dis:FindFirstChild("Humanoid")
		local Torso = Dis:FindFirstChild("UpperTorso")
		local Axe = Dis:FindFirstChild("Hacha")
		if Axe then
			if Human and Torso and Dis ~= script.Parent then
				if (RangeTronco.Position - Torso.Position).magnitude < Range then
					Range = (RangeTronco.Position - Torso.Position).magnitude
					target = Torso.Position
					Dis:FindFirstChild("Hacha"):FindFirstChild("TalarArbolAnim").Value = true
					if Dis:FindFirstChild("Hacha") then
						if HealtValueGuiEnabled.Value == false then
						script.Parent.HealthGui.Enabled = true
							HealtValueGuiEnabled.Value = true
						end
					end

				elseif (RangeTronco.Position - Torso.Position).magnitude > Range then

					if Dis:FindFirstChild("Hacha") then
						Dis:FindFirstChild("Hacha"):FindFirstChild("TalarArbolAnim").Value = false
						if HealtValueGuiEnabled.Value == true then
							script.Parent.HealthGui.Enabled = false
							HealtValueGuiEnabled.Value = false
						end
					end
				end
			end
		elseif not Axe then
			if Human and Torso and Dis ~= script.Parent then
				if (RangeTronco.Position - Torso.Position).magnitude > Range then
					local player = Dis
					local PlayerId = game.Players:GetPlayerFromCharacter(player)
					if PlayerId then --just a check
						local Backpack = PlayerId:WaitForChild("Backpack")
						if Backpack then
							local Axe = Backpack:FindFirstChild("Hacha")
							if Axe then
								Axe:WaitForChild("TalarArbolAnim").Value = false
								if HealtValueGuiEnabled.Value == true then
									script.Parent.HealthGui.Enabled = false
								end
							end
						end
					end
				end
			end
		end
	end
	return target
end


while wait(1.5) do
	local Enabled = DistanceToEnabled()
end
2 Likes