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

Finding if small portion is at start of players name?

Asked by 3 years ago

Hi,

So I'm making admin commands for my game. I want it so that ';kill noob' is the same as ';kill noob123'. I am curently using workspace:FindFirstChild(plr) (player is the first argument of the command). I know that it it will be something like:

if workspace:FindFIrstChild(game.Players:findFirstChild(str.find(plr), plr))

or something more complicated by going through each player in the game.Players to see if their name includes that, and if it does set the plr variable to the full name.

Whatever it is, I really need help. Anything would be greatly appreciated.

-Bizz

1 answer

Log in to vote
0
Answered by 3 years ago
function searchPlayer(searchName)

    searchName = "^"..searchName:lower() --Pattern in lowercase and ^ for searching at the beggining 

    for _, plr in pairs(game:GetService("Players"):GetPlayers()) do

        local plrName = plr.Name:lower() --Lowercase the player name

        if plrName:find(searchName) then  --Make the search and return the player if it's true
            return plr
        end

    end

end

searchPlayer("Holies")
0
it doesn't work BizzareBazaar 22 — 3y
Ad

Answer this question