I am currently making a relatively small and basic admin for myself but want to figure out how to be able to reference a player inside the game without having to type their full name out.
For example,
I want to be able to do: “.bring little”
Rather then: “.bring LittleBee5520”
Does anyone have any pointers on how you would do this or know any documentation that I may have missed that will help me?
-- Example
local username = "LittleBee5520"
local input = "LITTLE"
if username:lower():match(input:lower()) then
-- username:lower():find(input:lower()) would also work here
-- the messages matches the username
end
I didn’t need the whole command, I just needed to figure out a way to return players by finding them using an abbreviated version of their name. The solution attached to this thread works but I appreciate your input. Thanks ya’ll.
local Players = game:GetService("Players")
local Prefix = "."
Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
local split = string.split(message, " ")
local command = split[1]
local arg = split[2]:lower()
if string.sub(command, 1, 1) == Prefix and arg ~= nil and string.sub(command, 2, #command) == "bring" then
for _, v in pairs(Players:GetChildren()) do
if string.sub(v.Name:lower(), 0, #arg) == arg or string.sub(v.DisplayName:lower(), 0, #arg) == arg or v.Name:lower() == arg then
--Bring Player code
print("Found player: "..v.Name)
end
end
end
end)
end)
This should work if you say their display name, full name, or the first n letters of their name