How do I teleport the players to the part if they are outside of the zone?

I hope someone gets what I’m trying to say.

I want to teleport all players to the part if they are outside of the zone like in the Normal Elevator, when you are outside of the elevator you get teleported to the elevator, but when you are inside of the elevator you don’t get teleported, I even tried with A.I. script but it doesn’t work, what I got is this:

local randomSpawn = spawns[math.random(1, #spawns)]
local teleportZone = game.Workspace.Zone
	
for _, teleportPlayer in pairs(players:GetChildren())do
	if not teleportZone:FindFirstChild(teleportPlayer.Name) then
		teleportPlayer.Character.HumanoidRootPart.CFrame = randomSpawn.CFrame
	end
end

It’s working well, but they are even teleporting me to a random spawn even if I’m inside.

you are checking:

 teleportZone:FindFirstChild(teleportPlayer.Name)

are you ever setting the teleportPlayer.Parent to the teleportZone? If not you should check whether the player is touching the teleportZone or not, as opposed to checking if the player is a child of the teleportZone.

I found another way to this work, but I appreciate your help