So I have an admin command script, it works fine, but its a pain typing out the entire username of a player to do a command, I want the effect admin scripts such as Kohl's have, where a player can be found just from the start of their username
local function findplayer(name) for _,player in pairs(game.Players:GetPlayers()) do if string.lower(player.Name) == name then return player end end return nil end
This is the current function that finds the player, anyone know how I can edit it to make this possible?
local function findplayer(name) for _,player in pairs(game.Players:GetPlayers()) do if string.find ( string.lower(player.Name), name) then return player end end return nil end
You would use string.match()
.
local function findplayer(name) for _,player in pairs(game.Players:GetPlayers()) do local plr = string.lower(player.Name) if string.match(name, plr) then return player end end return nil end