generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: My amazing findPlayer function

Previous Thread :: Next Thread 
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
18 Mar 2014 11:51 PM
You're welcome.

function findPlayer(search)
for _,v in pairs(game.Players:GetPlayers()) do
if v.Name:lower() == search:lower() then
return v

elseif string.sub(v.Name:lower(), 1,#search) == search:lower() then
return v
end
end
end
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
18 Mar 2014 11:53 PM
Here, because shorter

function findPlayer(search)
for _, v in pairs(game.Players:GetPlayers()) do
if v.Name:sub(1, #search):lower() == search:lower() then
return v
end
end
end
Report Abuse
jakej78b is not online. jakej78b
Joined: 09 Mar 2011
Total Posts: 813
18 Mar 2014 11:53 PM
Amazing!
Report Abuse
flatline115 is not online. flatline115
Joined: 29 Jul 2013
Total Posts: 7826
18 Mar 2014 11:55 PM
I am amazed.
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
19 Mar 2014 09:33 AM
@cnt
But you didn't check to see if there is a player whose name is search.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
19 Mar 2014 09:38 AM
why would that matter? Either way if they put in the full name they still get the player and you can enter search just fine
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
19 Mar 2014 09:42 AM
What if there is a player named Player1 and a player named Player12. If you searched for "Player1", it would be ambiguous and may return the wrong player. Therefor, you check if the player's name IS search first.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
19 Mar 2014 09:48 AM
Oh, that's true actually
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
19 Mar 2014 09:55 AM
Yes. That particular part of the script is very important for the admin commands I'm working on.
Report Abuse
Aesthetical is online. Aesthetical
Joined: 01 Jan 2014
Total Posts: 2141
19 Mar 2014 10:13 AM
So all you have to do is call findPlayer()? So like,

findPlayer("Aesthetical")
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
19 Mar 2014 10:14 AM
findPlayer("Aesthetical"):Kick()

Yep. That would kick you.
Report Abuse
Aesthetical is online. Aesthetical
Joined: 01 Jan 2014
Total Posts: 2141
19 Mar 2014 10:15 AM
:(
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
19 Mar 2014 10:15 AM
Let me post the EXACT function from my admin commands script.

function findPlayer(search)
for _,v in pairs(game.Players:GetPlayers()) do
if v.Name == search then
return v
else
if string.sub(v.Name, 1,#search):lower() == search:lower() then
return v
end
end
return nil
end
Report Abuse
Aesthetical is online. Aesthetical
Joined: 01 Jan 2014
Total Posts: 2141
19 Mar 2014 10:16 AM
Okay. Well this will be useful in he future.
Report Abuse
KiwiTronik is not online. KiwiTronik
Joined: 18 Feb 2010
Total Posts: 3221
19 Mar 2014 03:53 PM
umg
a script..
that finds the player.. this was easier than i thought.
can i copy plox?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
19 Mar 2014 05:35 PM
You should make it more consistent though, like you are using methods and functions instead of just either one or both (string.sub(blah:lower())) just seems weird to me.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image