Detect player from textbox

Basically, I have a GUI with a textbox, and in the textbox, you write the player’s name and then all the functions work on that specified player.
Currently I have:

    for i,player in pairs(Players:GetChildren()) do
		...
	end

But it’s of course wrong, and I don’t know how to make it detect the player that was written in the TextBox

1 Like

Just detect if the text written in the TextBox matches the players name

local TextBox = -- define it 

for _,player in pairs(Players:GetPlayers()) do
      if player.Name == TextBox.Text then
           -- code
      end
end
3 Likes

Oh wow, I tried doing that but for some reason it didn’t work, probably forgot something. Thank you!

2 Likes

for some reason, after a specified amount of time, it stops working
code:

TextButton.MouseButton1Click:Connect(function()
	print("click")
	for _,player in pairs(Players:GetPlayers()) do
		if player.Name == TextBox.Text then
			print(player)
			WantedModule.Wanted(player)
		end
	end
end)
2 Likes

Code looks fine, try printing the contents of the textbox and see if it matches the player name

2 Likes

have u tried using string for the textbox?

1 Like

It does match the name, seems very strange

1 Like

String for textbox? never heard of it

1 Like

if it passes the if statement, then ur wanted function is probably the one that broken

1 Like

Nope, it does work if i activate it from my admin console

1 Like

it can tho i mean why not give it a try

1 Like

Does it pass the if statement? its also possible that your admin console actives the code on server, while the textbox actives the code locally

1 Like
TextButton.MouseButton1Click:Connect(function()
	print("click") -- it prints this
	for _,player in pairs(Players:GetPlayers()) do
		print(player) -- it also prints this
		if player.Name == TextBox.Text then
			print(player) -- but it doesnt print this
			WantedModule.Wanted(player, 150)
		end
	end
end)
1 Like

print(player,TextBox.Text,player.Name==TextBox.Text) -- it also prints this

Rewrite the print before the if statement with thisprint and tell me what it outputs

1 Like

It gives Retrofonik false
310chrs

1 Like
local players = game:GetService('Players')
local textbox = script.Parent

textbox.FocusLost:Connect(function()
	if textbox.Text ~= '' then
		local chosenPlayer = players:FindFirstChild(textbox.Text)
		if chosenPlayer then
			--Handler
		end
	else
		return
	end
end)
2 Likes

local Textbox = where the textbox is
local Button = add a button as a Search thing

Button.MouseButton1Press:Connect(function()
for _, Player in pairs(game.Players:GetPlayers()) do
if Player.Name = Textbox.Text then – because its not string, u have to be correct with capitalization
end
end
end)

2 Likes

based on the print it says you put 310crhs in the textbox?

1 Like

no, its gives Retrofonik false
i wrote 310chrs to let the dev forum send me the message

lol i forgot focus lost was a function so i used a button as an activator