Script keeps cloning

So, this is basically a phone which allows you to message players. It always refreshes to check if a player is not displayed on the phone, but for some reason it keeps cloning even though a player’s name has already been cloned.

Local Script:

local function refresh()
	for i, plr in pairs(game.Players:GetPlayers()) do
		for i, v in pairs(script.Parent:GetChildren()) do
			if v.Name == plr.Name then
				return
			else
				local clone = script.Parent.Layout:Clone()
				local players = game.Players
				clone.Parent = script.Parent
				clone.Name = plr.Name
				clone.TextLabel.Text = plr.Name
				clone.Visible = true
				clone.ImageLabel.Image = players:GetUserThumbnailAsync(plr.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
			end
		end
	end
end

while true do
	wait(1)
	refresh()
end

Personally I Would check if it the players name exists there after cloning and if it is not thers, parent it to where it needs to be.

Also, use task.wait instead of wait.

And usepcalls forGetUserThumbnailAsync

You should do the cloning inside of the first for loop and use the inner loop to see if the player is already cloned, which would look something like this:

for i, plr in pairs(game.Players:GetPlayers()) do
  cloned = false
  for i, v in pairs(script.Parent:GetChildren()) do
    if v.Name == plr.Name then
      cloned = true
    end
  end

  if cloned then
    -- clone
  end
end

Also, escaping the loop early can skip checking some players.