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: [SH] for i,v in pairs(table)

Previous Thread :: Next Thread 
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
22 Nov 2014 10:24 AM
I have this script

local tableItems = {"Tool","Tool2"} -- etc
for i,v in pairs(game.Players.LocalPlayer.Character:GetChildren()) do
for i,v in pairs(tableItems) do
if v.Name == tableItems then

It runs through the character, and looks for an equipped tool (in the character) with the name according to the table. This is my first time using i,v in pairs so I'm not really sure what is wrong. Any pointers from people experienced with i,v in pairs? Thanks
Report Abuse
SenseiWarrior is not online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
22 Nov 2014 10:26 AM
tableItems = {"Tool","Tool2"}

for _,v in pairs(game.Players.LocalPlayer.Character:GetChildren()) do
for _,c in pairs(tableItems) do
if v.Name == c then

--stuff

end
end
end
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
22 Nov 2014 10:34 AM
Couple of questions

With the c, you did that so that it wouldn't confuse between 2 v's?

is there a different between i,v and _,v?
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
22 Nov 2014 10:39 AM
Make it an enum

function enum(tab)
local mT = {}
local nT = {}
mT.__newindex = function(t,k,v)
rawset(t,k,v);
rawset(t,v,v);
table.insert(t,v); -- Uses rawset anyway, cheeky thing.
end
mT.__index = tab; -- Incase something was somehow missed out...
for k,v in pairs(tab) do
nT[k] = v;
nT[v] = v;
table.insert(nT,v);
end
return setmetatable(nT, mT);
end

tableitems = enum{"Tool", "Tool2"}
for _,v in pairs(game.Players.LocalPlayer.Character:GetChildren()) do
if tableitems[v.Name] then
--stuff
end
end
Report Abuse
lordrambo is not online. lordrambo
Joined: 16 Jun 2009
Total Posts: 20628
22 Nov 2014 10:47 AM
local tableItems = {"Tool","Tool2"} -- etc
for i, item in pairs(tableItems) do
if game.Players.LocalPlayer.Character[item] then
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
22 Nov 2014 10:49 AM
Doesn't that throw an error if it doesn't exist? Hehe.
Use :FindFirstChild() instead
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