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 autocomplete usernames without string.match()?

I'm trying to make a script where you can set a variable as someone's name then it auto completes it.

Ex:

Variable = "Sim"

Output = SimplyJeremy

I've tried using string.match with this but it usually bugs out and prints multiple players. Can someone please give me a better method without string.match?

1 comment

0

Isn't it possible that it's outputting multiple players because multiple players match the pattern "Sim.*"?

1 answer

✓ Accepted answer

To do this, you can create a function that checks the beginning of the username of all the players in the game. Here's an example that will print the first name starting with Sim:

function getFullName(Text)
	for Index, Player in pairs (game:GetService("Players"):GetPlayers()) do --Sort through players
		if string.sub(string.lower(Player.Name), 0, string.len(Text)) == string.lower(Text) then --Check if first part of name matches.
			return Player.Name --Return the player's name
		end
	end
end

wait(1)

print(getFullName("Sim"))

Let me know if you need any help!

1 comment

0

Much better

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