Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Does anyone know how to find a player without there full name?

Asked by 3 years ago

Hello! I am making a admin panel, I would like to know how to find a player without there full username.

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

Welcome to the world of RegEx (Regular Expressions).


In ROBLOX, RegEx is referred to as String Patterns. These are, in context, specialized character sets that can be used to search and break down strings. When combined with particular functions, they can be extremely powerful!

I highly recommend reading up on the documentation provided in the hyperlink above!


In today's case, we'll be using a method of String known as :match(). This is the most commonly used function when concerning low-level RegEx problems. This function will confirm whether the specified fragment or pattern belongs or conforms to the string of text we are comparing to, which will be the Player's username; returning the piece of the string that matches our condition, or nil.

We won't be doing anything complex, as we only really need to use one special character, known as an anchor when performing our comparison. This character will ensure the pattern starts at the beginning of the string: ^. (Making sure it doesn't locate the piece at different places in their name, experiment with this by removing that special character)

If we combine the half-name with the full name and determine whether it can be found by pressing it to the start, we can accomplish your goal. Here I will demonstrate this by manipulating the return result to represent a Boolean expression:

local ExampleName = "Ziffixture"

local FragmentedSearch = "Ziff"

print((ExampleName:match('^'..FragmentedSearch) ~= nil)) 

--> true (Otherwise "Ziff")

Now that you understand, all that's needed is to iterate through each player in-game and determine who matches our search parameters. I will use a function to return the located Player:

local Players = game:GetService("Players")


local function GetPlayerWithName(Name)
    for _, Player in pairs(Players:GetPlayers()) do
        ---------------
        if (Player.Name:match('^'..Name)) then
            ---------------
            return Player
        end
    end
end
0
Ok! noah01q 5 — 3y
Ad

Answer this question