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

How would you find and return a player with only part of their name?

Asked by 10 years ago

For ex, typing /admin roy would admin the user Royboy1234.

1 answer

Log in to vote
1
Answered by
RAYAN1565 691 Moderation Voter
10 years ago

The find function of the string library can be used to check if a string contains another string and you can make the check not case sensitive by using the lower case versions of both strings.

To check if the string source is part of the name of a player player, you can use player.Name:lower():find(source:lower(), 1, true). This will evaluate to true if the lower case name of the player contains the lower case string. The true in the last argument is there in order to tell the find function that it should not use string patterns and the 1 preceding it is there because the initial position must be given when a plain match is performed (which is the case here because the last argument is true).

Ad

Answer this question