How to find players using abbreviations

Hi all,

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?

Thanks,
LittleBee5520

You can use the match or find method for strings:

-- 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
3 Likes

Would you want the command to work on your self and other playeres

So all I would need to do is convert the list of players into a table and then loop through it?

Yes:

for _, player in game:GetService("Players"):GetPlayers() do
  local username = player.Name
  -- check username for command
end
3 Likes

Alright, I will try this now and see if it works. Thanks man!

Could you respond to my message?

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.

1 Like

This should work, you can modify this

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

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.