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

How to find a player without typing their full name in a textbox?

What I mean:

When you type "Magic", it finds the player who starts with "Magic" and goes to "Magicboopoo".

How do I do this?

I want to complete my admin GUI with new features. And this is one I've hoped for for a while.

1 answer

✓ Accepted answer

You can use string patterns to accomplish this. All you need to do is loop through all the players in the game and check to see if there is a substring (anchored to the beginning using the ^ anchor) that matches what was given. It may also be convenient to ignore case using the lower method in the string library.

Example assuming you are in the game:

local function getPlayerFromSubstring(substring)
	for _, player in ipairs(game.Players:GetPlayers()) do
		if string.lower(player.Name):match("^"..string.lower(substring)) then
			return player
		end
	end
	return nil
end

print(getPlayerFromSubstring("Magic"))
-- Output: Magicboopoo

1 comment

0

deleted comment lol

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