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

How would you find the closest player name to what you typed?

Asked by 7 years ago

Example: The player's name is "lolnuub0204" and i only typed "lol." How would i make a script that finds "lolnuub0204" from just "lol"?

2 answers

Log in to vote
0
Answered by 7 years ago

string.find()

Ad
Log in to vote
0
Answered by 7 years ago

This function will return a table of all players that match the search query.

findMatches = function(Query)
    local Matches = {}
    for i, v in pairs(game.Players:GetPlayers()) do
        if string.sub(string.lower(v.Name), 1, #Query) == string.lower(Query) then
            table.insert(Matches, v)
        end
    end
    return Matches
end

for i, v in pairs(findMatches("lol")) do
    v.Character.Humanoid.Health = 50
end

Answer this question