Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you autocomplete usernames without string.match()?

Asked by 6 years ago
Edited 6 years ago

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?

0
Isn't it possible that it's outputting multiple players because multiple players match the pattern "Sim.*"? fredfishy 833 — 6y

1 answer

Log in to vote
2
Answered by
popeeyy 493 Moderation Voter
6 years ago

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!

0
Much better User#24403 69 — 6y
Ad

Answer this question