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 » Scripters
Home Search
 

Re: Most efficient way to check table for string?

Previous Thread :: Next Thread 
sioux123 is not online. sioux123
Joined: 18 Nov 2011
Total Posts: 970
29 Jul 2016 04:10 AM
Have a table of usernames

local list = {
"sioux123",
"FROZENAURA"
}

game.Players.PlayerAdded:connect(function(player)
if list[player.Name] then
--do stuff
end
end)

--for some reason idk
i have done nothing with tables
Report Abuse
nacker is not online. nacker
Joined: 06 Oct 2009
Total Posts: 6034
29 Jul 2016 04:13 AM
you need to give your table some values... try this

local list = {
["sioux123"]=true,
]"FROZENAURA"]=true
}
Report Abuse
sioux123 is not online. sioux123
Joined: 18 Nov 2011
Total Posts: 970
29 Jul 2016 04:15 AM
if it has no values is it called an array
Report Abuse
RoyStanford is not online. RoyStanford
Joined: 21 Oct 2008
Total Posts: 2222
29 Jul 2016 05:14 AM
for index,value in pairs(list) do
if value == "FROZENNAURA" then
return index, value
end
end

http://wiki.roblox.com/index.php?title=Function_dump/Basic_functions#pairs
http://wiki.roblox.com/index.php?title=Loops#For
Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
29 Jul 2016 07:14 AM
local List = {
"DurstAuric",
"Player1",
}
function ScanTable(Table, Result)
for _, Value in pairs(Table) do
if (Value):lower() == (Result):lower() then
return true
end
end
end
game:GetService("Players").PlayerAdded:connect(function(Player)
if ScanTable(List, Player.Name) then print(Player.Name .. " has joined and is in the list.") end
end)


( ͡• ◡ ͡•) -=[ RAP: 350,892 || DurstAuric; the narb of ROBLOX ]=- ( ͡• ◡ ͡•)
Report Abuse
DevVince is not online. DevVince
Joined: 08 Nov 2008
Total Posts: 9245
29 Jul 2016 07:34 AM
--Do you mean this?
Array = {'String1', workspace, 'String2', nil, 46453555, 'String3'}
for i,v in pairs(Array) do
if type(v) == 'string' then
print(v)
end
end
Report Abuse
UFAIL2 is not online. UFAIL2
Joined: 14 Aug 2010
Total Posts: 6905
29 Jul 2016 08:21 AM
Do what nacker posted most efficient and most compact code.
Report Abuse
DevVince is not online. DevVince
Joined: 08 Nov 2008
Total Posts: 9245
29 Jul 2016 08:24 AM
You shouldn't use Usernames, there's this thing called name changing only one thousand Robux to do so. Use UserId's.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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