Im making a ban command, is there a better alternatives to string:match(string)

So I’m currently making a ban command for my admin, what I’m currently trying to achieve is that so player don’t have to write the full name of the person they are trying to ban. I’m currently using string:match(string) to find the player but it’s a little bit buggy.

Is there another way to find a player without the need of writing the full name?

My code:

if cmd == prefix.."pban" and level5 then
			if args[2] == nil then
				local gui = script.Parent.Guis.ErrGui:Clone()
				gui.ErrText.Text = "PLEASE ENTER A USER TO BAN"
				gui.Parent = player.PlayerGui
				game:GetService("TweenService"):Create(player.PlayerGui.ErrGui.ErrText, TweenInfo.new(1), {TextTransparency = 0}):Play()
				wait(1)
				game:GetService("TweenService"):Create(player.PlayerGui.ErrGui.ErrText, TweenInfo.new(1), {TextTransparency = 1}):Play()
			elseif level5 then
				for _,players in pairs(game.Players:GetChildren()) do
					if string.lower(players.Name):match(string.lower(args[2])) then
						players:Kick(pb)
						datastore:SetAsync(players.UserId, true)
					end
				end	
			end
		end

You could try using string.find(). I don’t know if it will work in your case, I don’t know what you set args[2] equal to, but you could try.

2 Likes

it actually works thank you so much

1 Like

No problem! I’m happy to help!

find and match use the exact same string pattern system, so there should be no difference there. Find just returns numbers while match returns a string.

2 Likes