|
| 29 Apr 2017 10:31 AM |
how do I correctly find a variable in a table?
example:
local tab = { }
local player = game.Players.LocalPlayer
table.insert(t, player)
how do I find the player variable in the tab table...
local p = tab[player] ???? idk |
|
|
| Report Abuse |
|
|
|
| 29 Apr 2017 10:33 AM |
local tbl={}
tbl[#tbl+1]=game.Players.LocalPlayer.Name |
|
|
| Report Abuse |
|
|
|
| 29 Apr 2017 10:35 AM |
is there anyway to not need a number to find the player variable?
such as tab[player] or some similar method that works |
|
|
| Report Abuse |
|
|
|
| 29 Apr 2017 10:36 AM |
| otherwise, I have to loop thru the table to find the player |
|
|
| Report Abuse |
|
|
|
| 29 Apr 2017 10:37 AM |
local p=tbl[game.Players.LocalPlayer.Name]
print(p) |
|
|
| Report Abuse |
|
|
| |
|
| |
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 29 Apr 2017 11:02 AM |
I guess.
local tab = {game.Players.LocalPlayer}; local player = game.Players.LocalPlayer local p;
for _,v in next,tab do if v == player then p = v; end end
print(p);
|
|
|
| Report Abuse |
|
|
|
| 29 Apr 2017 11:55 AM |
Add `break` in there so it doesn't continue iterating for no reason.
|
|
|
| Report Abuse |
|
|