ModuleScript[NPC_ID] = {} Replaces all current tables

  1. What do you want to achieve?

  2. What is the issue?
    Basically whenever using a method where you insert something inside a table using its name it seems to be replacing all current stuff inside that table which is odd??

  3. What solutions have you tried so far? Searched all over the devforum, seen if chatgpt could identify the issue but openai was down, im left with one choice(to create a topic post)

Here’s my code

-- Code


RemoteEvents:WaitForChild("SupermarketTill_Events"):WaitForChild("InsertNPCInTableLine").OnServerInvoke = function(plr,RandomTillName,NPC_ID,AccessCode)
	ModuleScript = require(game.ReplicatedStorage:WaitForChild("ModuleScript"))
	
	print("NPC ID:",NPC_ID)
	
require(game.ReplicatedStorage:WaitForChild("ModuleScript")).CurrentTills[RandomTillName].InLine[NPC_ID] = {ID = NPC_ID}

	ModuleScript = require(game.ReplicatedStorage:WaitForChild("ModuleScript"))
	
	print("ADDED TABLE! ",ModuleScript.CurrentTills)
	
	game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("ModuleScriptRemoteEvents"):WaitForChild("GiveClientModuleData"):InvokeClient(plr, ModuleScript)
	
end

Why do you call the module so many times?

Also if there is already an NPC_ID are in the inline area why do you need to create a table with the name of itself?

Pretty sure you can just do Module.CurrentTills[RandomTillName].InLine[NPC_ID] = {["Id"] = NPC_ID}

what are you trying to do sending the modulescript to the client btw

try if this works, if not, please send me the code inside the “ModuleScript”

RemoteEvents:WaitForChild("SupermarketTill_Events"):WaitForChild("InsertNPCInTableLine").OnServerInvoke = function(plr,RandomTillName,NPC_ID,AccessCode)
	local ModuleScript = require(game.ReplicatedStorage:WaitForChild("ModuleScript"))

	print("NPC ID:",NPC_ID)
	ModuleScript.CurrentTills[RandomTillName].InLine[NPC_ID] = {ID = NPC_ID}
	print("ADDED TABLE! ",ModuleScript.CurrentTills)
	
	game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("ModuleScriptRemoteEvents"):WaitForChild("GiveClientModuleData"):InvokeClient(plr, ModuleScript)

end

I’m giving it the updated modulescript since it doesn’t seem to be accessing it on the client, i was gonna use returning but an error happened on that remote event and i thought that i should try a technique that i used in a game called RoDonate, So i decided to not return it on the client for the time being.

module scripts dont replicate server/client.

can you do a before and after output of the module script so i can see how its replacing everything.

sending a table in that case is perfectly fine btw

Oh ok, so just to summarize, you want me to print it out without sending module data, basically printing out on the client using print(require(game.ReplicatedStorage.ModuleScript).CurrentTills)

yes, as well as after you’ve inserted the table