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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|