I’m making a ban command and I’m trying to make it so you don’t have to type the full name.
So let’s say there’s one of those dsqhDHQZHDSIQHQ accounts, I want to be able to type :ban dsqhdh (not case sensitive). How would I do that?
I’m making a ban command and I’m trying to make it so you don’t have to type the full name.
So let’s say there’s one of those dsqhDHQZHDSIQHQ accounts, I want to be able to type :ban dsqhdh (not case sensitive). How would I do that?
local function GetPlayer(String)
for i,v in pairs(game.Players:GetPlayers()) do
if (string.sub(string.lower(v.Name), 1, string.len(String))) == string.lower(String) then
return v
end
end
end
GetPlayer("dsqhdh") --// if dsqhDHQZHDSIQHQ is in game it will return him
Edit: Fixed typo and made it cleaner.
string.find() is your best friend
(jk its not lol). you can do something like:
function getplayer(targetplayer)
targetplayer = string.upper(targetplayer)
for _, player in pairs(game.Players:GetPlayers()) do
local name = string.upper(player.Name)
if string.find(name, targetplayer) then
return player
end
end
return false
end
Note that the indentation is horrible because I wrote it on forums. and also note that “targetplayer” has to be all uppercase (use string.upper(targetplayer) or something like that)
You could do this but its harder to understand then just straight up using string.find(). Good stuff though :D.
Thanks to everybody I’ll try what you guys said. (by the way didn’t need to give me the code but it’s appreciated!)