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: Quick table.insert question.

Previous Thread :: Next Thread 
iFallenAtlantis is not online. iFallenAtlantis
Joined: 29 Feb 2012
Total Posts: 240
28 Feb 2016 01:46 AM
I know how to insert values into a table, but after 30 minutes of searching, I haven't found a way to add a key to a table. I currently have:

local isAdmin = {}
table.insert(isAdmin, player.Name == true)

The player variable is a parameter of the game.Players.PlayerAdded:connect function, by the way.

Could someone help me out?
Report Abuse
OzzyFin is not online. OzzyFin
Joined: 07 Jun 2011
Total Posts: 3600
28 Feb 2016 01:49 AM
that would add a boolean depending if player.Name is true

table[key] = value
Report Abuse
iFallenAtlantis is not online. iFallenAtlantis
Joined: 29 Feb 2012
Total Posts: 240
28 Feb 2016 01:54 AM
Well, what I want is a boolean with the name of player.Name, then.
Report Abuse
OzzyFin is not online. OzzyFin
Joined: 07 Jun 2011
Total Posts: 3600
28 Feb 2016 01:56 AM
I gave you the answer
table[key] = value
Report Abuse
iFallenAtlantis is not online. iFallenAtlantis
Joined: 29 Feb 2012
Total Posts: 240
28 Feb 2016 02:01 AM
It's still printing false.
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
28 Feb 2016 02:19 AM
isAdmin[player.Name] = true;

With your table.insert code, you're comparing 'player.Name' with 'true'. Since they aren't the same thing, it will return false.

Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
Report Abuse
iFallenAtlantis is not online. iFallenAtlantis
Joined: 29 Feb 2012
Total Posts: 240
28 Feb 2016 02:29 AM
Ah, thank you. I'll have to try that in the morning. I'm tired.


Also, I like how one little symbol can mess up your whole script. Syntax is a demon. Lol



-I can put my waits wherever I want.
Report Abuse
128Gigabytes is not online. 128Gigabytes
Joined: 17 Apr 2014
Total Posts: 3616
28 Feb 2016 03:41 AM
Are you talking about ;?
It does nothing important Lua, expect it can be used in tables in plade of commas (And looks much nicer in my opinion)
It also declares that this is the end of a line, pointless since you can just add a new line, or just replace all new lines with a spade and not effect your code at all.

You can put it on the end of all your lines, or on none of them, or use them when you want to.
I personally use them for tables in place of commas

local array = {"a"; "b"; "c";}
local dictionary = {
["a"] = 1;
["b"] = 2;
["c"] = 3;
}

And when I set a key to a table
dictionary["d"] = 4;

And when I return a value from a function
local function add(x, y)
return (x + y);
end

And also when I am declaring a local variable but not setting it to a variable (So making it nil)

local example = nil
is the same as
local example = nil;
is the same as
local example
is the same as
local example;

I use the last one because it looks nicer to me.
Report Abuse
iFallenAtlantis is not online. iFallenAtlantis
Joined: 29 Feb 2012
Total Posts: 240
28 Feb 2016 11:33 AM
Ok.. So, as Gigabytes explained, adding the semicolon changed nothing.

I have this:

local isAdmin = {}
table.insert(isAdmin, isAdmin[player.Name] == true)
wait(1)
print(isAdmin[1])

What do I need to change, because it's still printing false.
Report Abuse
128Gigabytes is not online. 128Gigabytes
Joined: 17 Apr 2014
Total Posts: 3616
28 Feb 2016 11:46 AM
You need to completely take out the table.insert and just do

table[key] = value;

Example

local dictionary = {
["a"] = true;
["b"] = true;
}

dictionary["c"] = true;
print(dictionary["c"]) --[[> true]]
Report Abuse
iFallenAtlantis is not online. iFallenAtlantis
Joined: 29 Feb 2012
Total Posts: 240
28 Feb 2016 11:54 AM
That won't work for me, because most of that code is in a game.Players.PlayerAdded:connect function.

I am trying to make a group admin script, that checks the player's rank in a group when they enter. Then, add them to the table as either true if they are a high enough rank, or false if they aren't.

Is there really no way to add a key to a table?
Report Abuse
128Gigabytes is not online. 128Gigabytes
Joined: 17 Apr 2014
Total Posts: 3616
28 Feb 2016 11:57 AM
Listen to us

dictionary's have no order so nothing can be "inserted"
You can set a keys value

like we showed you
You can set the players name (the key) to the value (true)
This will work for what you want.
Report Abuse
iFallenAtlantis is not online. iFallenAtlantis
Joined: 29 Feb 2012
Total Posts: 240
28 Feb 2016 12:04 PM
Ah, I'm still tired, it's the morning. Lol. Sorry I didn't look a little closer. I got it to work.
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