Name shortening in chat

Hi

I was wondering how I could have the player type in a shortened name when using my chat commands. Lets take my name for example. Someone could type “/message Pen” instead of “/message Penguin22305”

Thanks

Heres something I use for shortened player names

function findplayer(playername)
	if playername == "me" then
		return game.Players.x1_EE -- change this to your name
	else 
		for index, player in game.Players:GetPlayers() do
			if string.find(string.lower(player.Name), string.lower(playername)) then
				print("Found player: " .. player.Name)
				return player
			end
		end
	end
end

Hey! Thanks for the help. Is “playername” the name that is typed in chat? I also don’t really understand this bit:

You could use something like that

for _,player in pairs(game:GetService("Players"):GetChildren()) do
	if string.match(player.Name:lower(), "^"..target.Name:lower()) then
       --code here
   end
end

Btw @x1_EE solution will have issue what if let’s say Player name is Player1, and if you type er it will still find Player1, which is kinda weird. string.find looks if keywords provided is even exists in other string. When string.match checks if string starts with these keywords.

Here is some screenshots of what will happen:
string.find -
image
image

string.match -
image
image