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

How do I located users in a text box??

Asked by 5 years ago
Edd= script.Parent.Parent
function getPlayer(name)
 local returned = {}
 for i, v in pairs(game.Players:GetPlayers()) do
  if v.Name:sub(1, Edd.BoxPlayer.Text()):lower() == name:lower() then
   table.insert(returned, v)
  end
 end
 return returned
end?

I am trying to do a admin panel and when someone types like a short version of a name to do that command on a text box. For example The text box would say y8 then you would kill y8pogo123589 when you press the kill button.

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Match function


There main way you would do this is with the string.match function, and iterating thought the list of players:

The way the match function is formatted is like such:

string.match(String,Pattern,start,finish)

Note that these aren't the official names used on the wiki.

The Match function returns either pattern that is found, or nil, which makes it a great way to detect is a string contains a particular pattern.


Application


With that said, here would be an example:

local function GetPlayer(Text)
    local plrs = {}
    for _,plr in pairs(game.Players:GetPlayers()) do
        if (plr.Name:lower()):match(Text) then
            table.insert(plr,plrs)
        end
    end
    return plrs
end

One other thing to note is that it is better practice to use local variables in the global scope rather than global variables (variables defined without local).

Hopefully This Helped!

Ad

Answer this question