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 4 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:

1if 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 4 years ago
01function searchPlayer(searchName)
02 
03    searchName = "^"..searchName:lower() --Pattern in lowercase and ^ for searching at the beggining
04 
05    for _, plr in pairs(game:GetService("Players"):GetPlayers()) do
06 
07        local plrName = plr.Name:lower() --Lowercase the player name
08 
09        if plrName:find(searchName) then  --Make the search and return the player if it's true
10            return plr
11        end
12 
13    end
14 
15end
16 
17searchPlayer("Holies")
0
it doesn't work BizzareBazaar 22 — 4y
Ad

Answer this question