Detect if there is a player name of all

I need to make the script detect if the text matches at least someone’s player name. If it is possible to do this without loops. I guess it’s done through “string.match()” but I don’t understand how to use it. Here is my script:


local players = game.Players:GetChildren()

script.Parent.Parent.CheckButton.MouseButton1Click:Connect(function()
   if script.Parent.Text ~= players then -- there is check line
      print("This player doesn't exist")
   else
      print("yaaaaa")
   end
end)

1 Like

Because you want to compare it to all players, you have to use a loop

2 Likes

Try this maybe?

script.Parent.Parent.CheckButton.MouseButton1Click:Connect(function()
	for i,plr in ipairs(game.Players:GetPlayers()) do
		if script.Parent.Text ~= plr.Name then
			print("Text isnt equalt to player Name of : "..plr.Name)
		end
	end
end)
1 Like

This should work :

script.Parent.Parent:WaitForChild("CheckButton").MouseButton1Down:Connect(function()
	for i, player in pairs(game.Players:GetChildren()) do
		if player:IsA("Player") then
			if script.Parent.Text ~= player.Name then
				print("sus")
			else
				print("amogus")
			end
		end
	end
end)
1 Like
local Players = game:GetService("Players")

script.Parent.Parent.CheckButton.MouseButton1Click:Connect(function()
	if Players:FindFirstChild(script.Parent.Text) then
		print("Player is on server")
	end
end)
1 Like

this is exactly what i wanted, thank you a lot !