Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Finding if small portion is at start of players name?

Hi,

So I'm making admin commands for my game. I want it so that ';kill noob' is the same as ';kill noob123'. I am curently using workspace:FindFirstChild(plr) (player is the first argument of the command). I know that it it will be something like:

if workspace:FindFIrstChild(game.Players:findFirstChild(str.find(plr), plr))

or something more complicated by going through each player in the game.Players to see if their name includes that, and if it does set the plr variable to the full name.

Whatever it is, I really need help. Anything would be greatly appreciated.

-Bizz

1 answer

function searchPlayer(searchName)
	
	searchName = "^"..searchName:lower() --Pattern in lowercase and ^ for searching at the beggining 
	
	for _, plr in pairs(game:GetService("Players"):GetPlayers()) do
		
		local plrName = plr.Name:lower() --Lowercase the player name
		
		if plrName:find(searchName) then  --Make the search and return the player if it's true
			return plr
		end
		
	end
	
end

searchPlayer("Holies")

1 comment

0

it doesn't work

This discussion is preserved as it was. New answers, comments, and votes are closed.