Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Finding a player through a TextBox?

I tried making a script that finds a player through a textbox, but it won't work. Any help?

script.Parent.MouseButton1Down:Connect(function()
	local target = script.Parent.Parent.NewTeamPlayerBox.Text
	
	for _, player in pairs(game:GetService("Players"):GetPlayers()) do
		if player.Name:lower() == target:lower() then
		    print("hi")
	   end
	end
end)

1 answer

✓ Accepted answer

easy.

script.Parent.MouseButton1Click:Connect(function() --function the click event, when someone clicks the button.
	local Target = script.Parent.Parent.NewTeamPlayerBox.Text --variable "Target" will be used to indicate the text in the textbox.
	for Index, Player in pairs(game.Players:GetChildren()) do --"Player" will be used to indicate the children of game.Players
		if Player.Name:lower() == Target:lower() then --when they lower the text, it will check if the text matches the players name.
			print("hi") --print hi if it matches the players name.
		end
	end
end)

instead of having to use

game:GetService("Players")

you can just use

game.Players

since Players is already listed in the explorer.

This discussion is preserved as it was. New answers, comments, and votes are closed.