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

How do you make a script that auto completes names?

I'm trying to make a script where you can find someone's name by typing only the first few letters. Ex: A player's username is "testING123" and you type "testing" it will print "testING123" Can someone please help me with this?

1 answer

✓ Accepted answer

Well if you have a table of the players, you can use string.match to tell whether or not your search string is contained within any of the names.

Example:

local players = game.Players:GetPlayers()
local SearchString = "Simply"
local CompletedString = ""

for i,v in pairs(players) do
	if string.match(v.Name,SearchString) ~= nil then
		CompletedString = v.Name
		break
	end
end

This works because as according to the wiki: string.match will return the string that was found or nil.

So if we check the name against our search criteria we will either get nil or a valid string. If we get a valid string we know we can set the completed string to v.Name

The drawback of this specific method being that we return on the first object found, meaning there could be another player with the same name.

Another potential drawback is that this won't necessarily search from the start of a string, and could find the pattern at any point in the string.

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