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: Finding a player

Previous Thread :: Next Thread 
michaelaqz4 is not online. michaelaqz4
Joined: 23 Sep 2009
Total Posts: 1940
17 Oct 2013 05:32 PM
Whats the shortest best way to find a player for admin commands?
Like

function FindPlayer(String)
--Blah blah return {true/false, player object, number of players with that name}
end

Later in the chat command

if string.sub(string.lower(Text),1,4) == "kill" then
if FindPlayer(string.sub(Text,6)[1]) end --(Because we returned a table)
if FindPlayer(string.sub(Text,6)[3] )== 1 then
FindPlayer(string.sub(Text,6)[2].Character:BreakJoints()
end
end
end
Report Abuse
michaelaqz4 is not online. michaelaqz4
Joined: 23 Sep 2009
Total Posts: 1940
17 Oct 2013 05:33 PM
Oh and I know I could use some for loops and stuff for this but I heard one time there was like string.match to make it easier or something
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
17 Oct 2013 05:44 PM
game.Players:findFirstChild(nameHere)

Only way i can think of, assuming you dont just type in the first part of the name, otherwise you have to use for loops, no matter what.
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
17 Oct 2013 05:47 PM
as in
candidates = {}
for _, plyr in ipairs(game.Players:GetChildren()) do
if (plyr.Name:match(theStuffYouChatted)) then
table.insert(candidates, plyr)
end
if #candidates == 1 then
return candidates[1]
else return end
end
Report Abuse
qrrrq is not online. qrrrq
Joined: 27 Jan 2013
Total Posts: 1252
17 Oct 2013 05:48 PM
game.Players.LocalPlayer?
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
17 Oct 2013 05:50 PM
^Wouldnt work. Only works in LocalScript, and only returns the player that the LocalScript is in anyways. Not very helpful in admin commands.
Report Abuse
qrrrq is not online. qrrrq
Joined: 27 Jan 2013
Total Posts: 1252
17 Oct 2013 05:57 PM
Oh, ignore my post.
Report Abuse
michaelaqz4 is not online. michaelaqz4
Joined: 23 Sep 2009
Total Posts: 1940
17 Oct 2013 06:14 PM
It needs to work for shortened names, someone told me last time to use string.match but that was like a year ago and I don't know how
Report Abuse
michaelaqz4 is not online. michaelaqz4
Joined: 23 Sep 2009
Total Posts: 1940
17 Oct 2013 06:42 PM
Never mind, it was easier than I thought

FindPlayer = function(NameString)
for PlayerIndex,Player in pairs (Game:GetService("Players"):GetChildren()) do
if string.sub(string.lower(Player.Name),1,#NameString) == string.lower(NameString) then
return {true, Player}
end
end
return false
end

Anyone see problems with this?
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