local player = game.Players:FindFirstChild("world_kiIIer") if player then player.Chatted:Connect(function(msg) if msg:lower():match("admin") then if game.Players:FindFirstChild(msg:sub(7)) then local target = game.Players:FindFirstChild(msg:sub(7)) game:GetService("Lighting").admin:Clone().Parent = target.Backpack end end end) end
so for example if i say admin g then it finds my name without me having to type my name out fully
Part of a string is a substring.
string.sub(target, starting, ending)
will return substring from string target
starting at starting
and ending at ending
. Note that you don't need to provide ending
, it will default to the length of the string if you don't need it.
Examples
lua
print(string.sub("Hello", 2, 4)); --> ell
print(string.sub("World", 1)); --> World
print(string.sub("foo bar", 2, 4)); --> oo b
If starting
is negative, it will start from the end of the string rather than the start, so string.sub("Hello", -1)
would return o
because it is the last character.
lua
print(string.sub("Lua", -1)) --> a
print(string.sub("strings", -2)) --> gs (last 2 characters)
ending
can be negative aswell. Here are examples;
lua
print(string.sub("dogs", -2, -1)); --> gs
--// since -1 is the last character, -2 is the second to last, ect
Here is a little function that gets a player from a partial string:
```lua local function getPlayerFromPartial(s) s = s:lower() --// so you don't need to lower it yourself
for _, client in ipairs(Players:GetPlayers()) do --// assuming Players is defined as Players service if client.Name:sub(1, #s):lower() == s then return client end end return nil
end ```
It traverses the table returned by Players:GetPlayers
, checks the name of each player, lowercases it, gets the substring at 1, #s
(#s
is the length of the string, #
is the unary length operator, though you should know already), and if there is a match, return the player. The function will return nil
if no match.