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?
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!