Hello,
I'm working on an admin system.
In certain commands, an admin can specify a command to work on a particular player.
For example ;kill <player>
I wanted to make it so that the admin wouldn't have to specify the entire player name they wanted to effect.
For example, for me, instead of having to do ;kill Tweakified
, you could do ;kill Twea
How would this be achieved?
I thought of using :match
to do this. However, running ;kill ified
would also work.
Any advice/help you can give would be appriciated.
After doing some additional research, I found a solution to my problem:
From this
I was able to modify the code to check only the start of the string with using the ^
This is how I modified the code:
local function GetPlayerFromString(nameString) local matches= {} for _, player in ipairs (game.Players:GetPlayers()) do if string.lower(player.Name):match("^".. string.lower(nameString)) then table.insert(matches, player) end end if #matches== 1 then return matches[1] else return nil end end
Hope this helps someone in the future, Tweakified
I don't think that this type of thing is even possible. You need to put the Full Player's Username, as Lua it's Case Sensitive.
I'm conveniently doing the same thing. Here's my method:
local Players = game:GetService'Players'; local function GetPlayerFromSubString(Name) Name = Name:lower():reverse(); for _,a in pairs(Players:GetPlayers())do local b = (a.Name):lower():reverse(); if string.find(b,Name,#b-#Name)then -- Note: #(string) is the same as string.len return a; end; end; end;