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: table index is nil

Previous Thread :: Next Thread 
imaginaryUberlyuber is not online. imaginaryUberlyuber
Joined: 15 Jul 2012
Total Posts: 208
05 Feb 2017 02:55 PM
*PLEASE READ BEFORE COMMENTING*

Hey, so I'm trying to add something to a table in a ModuleScript (which further gets added to a datastore), so I'm using table[key] = {value}, the problem is when I do that, it tells me the table index is nil.

I get that it probably wants me to use table.insert(), but the thing is, I need to be able to add keys other than just 1,2,3 etc., as other scripts use those keys to identify which value to change, and (to my knowledge) table.insert doesn't let you do that.

So what am I doing with by using table[key] = {value}, and how do I add a key AND a value to the table without erroring?

Thanks.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
05 Feb 2017 02:57 PM
post both the ModuleScript code and the script requiring it


Report Abuse
imaginaryUberlyuber is not online. imaginaryUberlyuber
Joined: 15 Jul 2012
Total Posts: 208
05 Feb 2017 03:04 PM
--ModuleScript

indexes = {}

--Nonimportant Datastore stuff

function indexes.estabPoint(point,pointB, arg)
indexes[point] = {pointB = arg}
end

return indexes

--Script

function script.Parent.OnServerInvoke:connect(function(point,pointB,arg) --Yes, this is inside a RF, and yes I made sure it is being called, and none of the arguments are nil
indexes.estabPoint(point,pointB,arg) --the arguments are provided from a TextBox
end)

>ServerScriptService.IndexStatManager:44: table index is nil
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
05 Feb 2017 03:08 PM
once a ModuleScript is required once per server/client, it'll always return the same thing it did when it was required that first time
so even if you try to add another element to table indexes, it'll always return only indexes with function estabPoint


Report Abuse
imaginaryUberlyuber is not online. imaginaryUberlyuber
Joined: 15 Jul 2012
Total Posts: 208
05 Feb 2017 03:19 PM
Oh well that kinda sucks. Is there any way around that?
Report Abuse
imaginaryUberlyuber is not online. imaginaryUberlyuber
Joined: 15 Jul 2012
Total Posts: 208
08 Feb 2017 07:01 PM
^
bump
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
08 Feb 2017 07:07 PM
if you need the return value to be changed then just don't use modules


Report Abuse
imaginaryUberlyuber is not online. imaginaryUberlyuber
Joined: 15 Jul 2012
Total Posts: 208
08 Feb 2017 07:09 PM
I'm using DataStores.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
08 Feb 2017 07:11 PM
"I need to be able to add keys"

once you require a module, it'll have the same return value per who required it (server/client)

don't use modules for this if you need whatever is returned to be changed


Report Abuse
imaginaryUberlyuber is not online. imaginaryUberlyuber
Joined: 15 Jul 2012
Total Posts: 208
08 Feb 2017 07:12 PM
Yes, but as I said, I'm using DataStores, which requires (unless I'm incorrect) use of Modules.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
08 Feb 2017 07:12 PM
what gave you that idea?
I'd recommend reading up on data stores


Report Abuse
imaginaryUberlyuber is not online. imaginaryUberlyuber
Joined: 15 Jul 2012
Total Posts: 208
08 Feb 2017 07:14 PM
There's a table and I need scripts to access it. And it needs to save it's data across sessions, ergo the ModuleScript is needed.
Report Abuse
imaginaryUberlyuber is not online. imaginaryUberlyuber
Joined: 15 Jul 2012
Total Posts: 208
08 Feb 2017 07:15 PM
(Sorry for double post)

It should be the other way around, it needs a table with scripts accessing it, so a Module is needed.
Report Abuse
DJ3SkullsEden is not online. DJ3SkullsEden
Joined: 06 Dec 2016
Total Posts: 182
08 Feb 2017 07:15 PM
TL;DR on replies

If you're trying to access a table that's in 1 script, from another script, that won't work unless you use global variables or some other form of transferring variables.

Q: how do I add a key AND a value to the table without erroring?
A: First, make sure the table exists.

local t = {}

Second, choose your key name.

local key = "chedder"

Thirdly, choose your value's, er.. Value.

local value = 100

Finally, set your key's value within your table.

t[key] = value

If you're using a dictionary then this is one of the only ways to my knowledge. If this is wrong then someone please correct me.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
08 Feb 2017 07:15 PM
I don't think you understand the functionality of ModuleScripts at all
what makes you think they're required for data stores?


Report Abuse
imaginaryUberlyuber is not online. imaginaryUberlyuber
Joined: 15 Jul 2012
Total Posts: 208
08 Feb 2017 07:17 PM
Apparently you are wrong because that (sometimes) results in a table index is nil error. It isn't now for whatever reason, but I still need some way of transferring variables. Can the require function not be "refreshed" or whatever?
Report Abuse
imaginaryUberlyuber is not online. imaginaryUberlyuber
Joined: 15 Jul 2012
Total Posts: 208
08 Feb 2017 07:22 PM
You know what I'm going to try using _G and see how it works.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
08 Feb 2017 07:23 PM
I still don't know why you're hesitant to just handle it from a server script


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