How would I find a user without entering the full name?

I’m making a ban command and I’m trying to make it so you don’t have to type the full name.

So let’s say there’s one of those dsqhDHQZHDSIQHQ accounts, I want to be able to type :ban dsqhdh (not case sensitive). How would I do that?

local function GetPlayer(String)
	for i,v in pairs(game.Players:GetPlayers()) do
		if (string.sub(string.lower(v.Name), 1, string.len(String))) == string.lower(String) then
			return v
		end
	end
end

GetPlayer("dsqhdh") --// if dsqhDHQZHDSIQHQ is in game it will return him
2 Likes

Edit: Fixed typo and made it cleaner.

string.find() is your best friend :wink: (jk its not lol). you can do something like:

function getplayer(targetplayer)
	targetplayer = string.upper(targetplayer)
	for _, player in pairs(game.Players:GetPlayers()) do
		local name = string.upper(player.Name)
		if string.find(name, targetplayer) then
			return player
		end
	end
	return false
end

Note that the indentation is horrible because I wrote it on forums. and also note that “targetplayer” has to be all uppercase (use string.upper(targetplayer) or something like that)

You could do this but its harder to understand then just straight up using string.find(). Good stuff though :D.

1 Like

Thanks to everybody I’ll try what you guys said. (by the way didn’t need to give me the code but it’s appreciated!)