How would I get a player by only a few characters?

Hey there!

So I have an admin command script, but I want it to get players by only a few characters (like “player1” would be “player1234”).

How would I do this?

Any help is appreciated.

Is there a specific amount of characters?

Nope, there isn’t a specific amount of characters.

How is the game supposed to know what “a few” is?

You would want to use string.match(partialName, player.Name)

1 Like

Basically for example, if a player said ‘:ban flk’ then it would find the player with a close username to that and ban the player.

(I’m really stupid so yeah.)

Alright, I’ll try that out in my code.

1 Like

I wish you would of started with this. What you will want to do is get the partial part of a player’s name.

local function getPartialUsername(user)
	for i,v in ipairs(game.Players:GetPlayers()) do
		if string.find(string.lower(v.Name), string.lower(text)) then
			return v
		end
	end
	return false
end
3 Likes

This worked, thanks for helping me!

No problem, if you have another issue just post on the forums again.

What’s the “text” in string.lower(text)?