Error with Attempt to index nil with value

Hello, I tried to make a system where I send over a table and then on the client the table gets sorted into multiple other tables inside of one table. I got the table over and I was able to sort it but when i get down to the part where it checks to see if the object is inside of a table then I get an error saying attempt to index nil with 'value'. I don’t know what is causing this, can someone please help?

local Tables = {
	Table1 = {};
	Table2 = {};
	Table3 = {};
	Table4 = {};
}


local function AddItemToTable(tbl)
	print(tbl)
	local plr = Players.LocalPlayer
	local Table1 = Tables.Table1[plr.Name]
	local Table2 = Tables.Table2[plr.Name]
	local Table3 = Tables.Table3[plr.Name]
	local Table4 = Tables.Table4[plr.Name]

	for i,v in pairs(tbl) do
		print(v)
		print(i)

		local objType = ItemModule[i]["Type"]

		--Error happening here
		if i ~= Table1[i] or Table2[i] or Table3[i] or Table4[i] then
			Tables[objType][plr.Name][i] = Tables[objType][plr.Name][i] + 1
		elseif i == Table1[i] or Table2[i] or Table3[i] or Table4[i] then
			Tables[objType][plr.Name][i] = 1
		end
	end

	print(Table1, Table2, Table3, Table4)
end

Item Module:

local module = {
	["Sword"] = {
		Name = "Sword";
		Type = "Equipment";
		Model = Models.Sword;
		Desc = "Sword";
	};
}
return module
1 Like

Put this line of code before the for loop and tell me the output.

1 Like

ah, i see. It says nil, nil, nil, nil. Any idea how to fix it?

From where are u getting plr.Name variable? for local TableX = Tables.Table1[plr.Name]

Also show the hierarchy of the whole Tables array including the Table1,2,3, etc arrays

I get the players name from:

local Players = game:GetService("Players")
local plr = Players.LocalPlayer

This was working before but when I moved data from the server to the client and added a for loop then things didn’t work.

The main script containing the table should be a Server Script, and LocalScripts should send info to that ServerScript by remotes.
The script u are showing where it is? ServerScriptService? a part on Workspace? Its a Server or Client script?
I insist how are u getting the name of the players? Do u have a table of Players that joined and using that table to use their names to get info from this table you are showing?

If you are saving data into client LocalScripts, a table. Then many different tables are existing on each client, and those are not replicated to server.
Just add more context to your system to understand whats happening, or send a place file to check

I have a different script in ServerScriptService which contains the main information and then sends a copy to the client. On the client (stored in starterGui) the Information should be split into the four tables depending on a module script that contains item data which is in ReplicatedStorage. I don’t have a table that gets players, this script is on the client and gets the name of the player from local plr = game.Players.LocalPlayer.Name. I am not saving data to the client because all the infomation is on the server and a copy is being sent to the client from the server. Hope this helps.

I need to see the whole system to understand whats happening.
The module is called and written by the client? Its written by the sever? the table is on the SSS (ServerScriptServer) or the table is on the module?

How are u sending the table to each client? By using the module? by the SSS script?

I usually do systems like this, writting tables on modules and send them to clients, or writting tables on SSS sending them to clients, Im a little confused on your issue, would be helpful if you post the Module and the SSS script too. Cause ur only issue its that clients are not getting the tables, OR clients really doesnt know that plr.Name variable to access the table.

here is a link to the game. Im using the output to get values before I make a full ui.

By joining the game I cant see the scripts :v Whats the point? xD
I really wanna help, but I cant download it unless u make it open sourced, or better just save a local file and drag it here

EDIT: @peepo12343 extra, if you print the output on client ok, I could see it, but I cant join xD
image

my bad, I forgot to open source it. Its done now

1 Like

Ok, first, you are trying to get a local player from a server script, thats not possible

-- Server SIDE
local plr = Players.LocalPlayer

Then this local objType = ItemModule[i]["Type"] is not referenced in the script.

Let me check the whole file, cause theres some scripts that doesnt belong to the system in which u are having problems, so this will take me some time.

EDIT: @peepo12343 oh okie, that thing was on that one actually, sorry, let me check :3

don’t worry about the second script called script in ServerScriptService because that was me just playing around. Also in the local script in Starter Gui you can remove the line of code after the massive amount of space. (contains variables that are not referenced and was for something else)

Right now its late, and Im tired, I need a rest, sorry for not fixing ur system yet. But Im sure that you are saving nothing into the table made by the module, when the Add function runs after a player collects the “Sword” the only thing saved on the table is just an int with value 1.

When iterating on the table got from the module, prints 1, when checking the Add function on the module, its saving an int, thats why the table returned only has an int 1, and not the 4 four tables

if inventory[name] then
	print("wakamoles!!!")
	inventory[name] = inventory[name] + amount or 1
else
	print("wakamoles2!!!", amount)
	-- The table holds nothing just an int, after the Add function on module call
	inventory[name] = amount or 1
end

image

That last number 1 on the print is the table you are sending back. Due to the module only saving that integer, and not the whole table.

I will work on this later, Im really sorry, I gotta rest a little, but, the issue its that just you are not sending the full table back, so impossible for client to find that plr.Key into the dictionary. The problem is the module when adding new items and retrieving the data to the client.

ok, i understand now, Is there a way to fix this?

Hello, I was wondering if you found a solution?