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: variable in a table

Previous Thread :: Next Thread 
Nuclear_Energy is online. Nuclear_Energy
Joined: 21 Jul 2013
Total Posts: 1380
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
Gomlsauresrex is not online. Gomlsauresrex
Joined: 25 Mar 2016
Total Posts: 3588
29 Apr 2017 10:33 AM
local tbl={}

tbl[#tbl+1]=game.Players.LocalPlayer.Name
Report Abuse
Nuclear_Energy is online. Nuclear_Energy
Joined: 21 Jul 2013
Total Posts: 1380
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
Nuclear_Energy is online. Nuclear_Energy
Joined: 21 Jul 2013
Total Posts: 1380
29 Apr 2017 10:36 AM
otherwise, I have to loop thru the table to find the player
Report Abuse
Gomlsauresrex is not online. Gomlsauresrex
Joined: 25 Mar 2016
Total Posts: 3588
29 Apr 2017 10:37 AM
local p=tbl[game.Players.LocalPlayer.Name]

print(p)
Report Abuse
Nuclear_Energy is online. Nuclear_Energy
Joined: 21 Jul 2013
Total Posts: 1380
29 Apr 2017 10:38 AM
nil
Report Abuse
Nuclear_Energy is online. Nuclear_Energy
Joined: 21 Jul 2013
Total Posts: 1380
29 Apr 2017 10:46 AM
results in a nil value
Report Abuse
Goulstem is not online. 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
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
29 Apr 2017 11:55 AM
Add `break` in there so it doesn't continue iterating for no reason.


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