How to find which object is the closest to the player with my 2 objects

Hey, I have 2 specific objects and I need some help with finding the closet object to a player.
Then it would run a segment, I needed to do this because I realised the for i loop checks those 2 objects without finding the closest one.
My script:

local players = game:GetService("Players")
local player = players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")
local distance = 20
local tweenservice = game:GetService("TweenService")
local info = TweenInfo.new(
	0.3,
	Enum.EasingStyle.Quad,
	Enum.EasingDirection.InOut,
	0,
	false,
	0
)
local function nearnextbot()
	for i, v in pairs(workspace:GetChildren()) do
		local target = v
		--local poop = player.Team == Teams["noobs"]
		--local poop1 = player.Team
		if target and target.Name == "saulcone" or target.Name == "selene" then
			local target2 = v.HumanoidRootPart
			if (target2.Position - hrp.Position).Magnitude <= distance then
				print("play")
				if script.Parent["Running Chase b"].Playing == false then
					script.Parent["Running Chase b"]:Play()
				end
				tweenservice:Create(script.Parent["Running Chase b"], info, {Volume = 1}):Play()
				tweenservice:Create(script.Parent.ImageLabel, info, {ImageTransparency = 0}):Play()
			elseif (target2.Position - hrp.Position).Magnitude >= distance then
				tweenservice:Create(script.Parent.ImageLabel, info, {ImageTransparency = 1}):Play()
				print("end")
				tweenservice:Create(script.Parent["Running Chase b"], info, {Volume = 0}):Play()
				task.wait(0.3)
				script.Parent["Running Chase b"]:Stop()
			end
			end
		end
	end
while true do
	task.wait(0.2)
	nearnextbot()
end

This script has a problem that needs to be replaced which is

if target and target.Name == “saulcone” or target.Name == “selene” then

The script is in LocalScript

Try this instead:

if not target then return end

if target.Name == "saulcone" or target.Name == "selene" then
       -- Keep going
end

It’s not really what im looking for, you know saul cone and selene, those are my 2 objects, the if statement will play the print out “play” and “end”, this means im close to one object BUT the other object is far so it will play those 2 if statement within the if statement that checks saul or selene.
I want to only find out of those 2 the closest one

Well, with your error information provided that is your issue. Until more information I can’t help.