Why is the table making the objects go into thin air

So called table “Rooms” keeps removing my objects from itself.
That causes a lot of problems because I can’t render rooms properly and it leads to idiotic bugs.

module.AddRoom = function(RoomObject)
	local RoomNode = UI:WaitForChild("RoomNode"):Clone()
	local RoomNodeClass = require(RoomNode:WaitForChild("RoomClass"))
	Rooms[RoomObject.HostId] = RoomNodeClass
	print(RoomObject.HostId) 153th line

module.RemoveRoom = function(RoomNodeClass)
	Rooms[RoomNodeClass.Host] = nil
module.UpdateRooms = function(RoomsTab)
	local ToAdd = {}
	local ToUpdate = {}

	for RoomId,Room in pairs(RoomsTab) do
		local IsExistant = not not Rooms[RoomId]
		print(IsExistant,"Is Existant")
		if not IsExistant then
			ToAdd[RoomId] = Room
			ToUpdate[RoomId] = Room
	local Added = 0
	local Changed = 0
	local Removed = 0
	for RoomId,Room in pairs(ToAdd) do
		print(RoomId) 183th line
		Added += 1

	for RoomId,Room in pairs(ToUpdate) do
		Changed += 1
	for RoomId,Room in pairs(Rooms) do 
		if ToAdd[RoomId] or ToUpdate[RoomId] then
		Removed += 1

Those are all functions related to Rooms dictionary.

Keep in mind that server stores player data in a script that isn’t bugged.
So the last output message is correct. I have been trying for hours to debug.

1 Like

I see that it prints “Removed” in the output, but not in your code. Where is that printed from? Are you sure you may not call the script to remove it from some previous test script etc?

A double negation cancels out btw.

the removed thingie is from the Node.Remove() it’s lines don’t exist when script’s parent is null (probably)
double negation was to receive a bool.

Alright, smart. Your final for loop, are you certain the continue works as you intend? I would consider changing it to:

for RoomId,Room in pairs(Rooms) do 
	if not (ToAdd[RoomId] and ToUpdate[RoomId]) then
		Removed += 1

Even though you are doing the right thing avoiding nesting inside if-statements.
EDIT: I forgot to make this clear initially, I see nothing wrong with the way it is written.

On a side-note, you are writing your module functions rather weird, usually you would write:

function module.Remove()

I am not kidding
LuaU is having a stroke or something, so the if statement you gave me wouldn’t work.
I am not “multithreading” it btw.

Ignore my last reply, didn’t really make a lot of sense. Have you tried printing out the tables ToAdd and ToUpdate? As well as printing out ToAdd[RoomId] etc. Might be that some data doesn’t work as intended?

It can’t be
Well about the ToAdd[RoomId], it is a nil for some reason
Ignore Removed and Previous rooms, those variables ain’t being used in any way (for now)

If you print them out, what are their contents? Your or statement wouldn’t work if the value of ToAdd[id] == false for example. I doubt that will be the case, but considering your false Is Existant (which means the original value was false since it was double negated) it means that there is a possibility that the value is simply false, meaning that the or statement won’t accept it.

Then the Add function would spit out an error that HostId is a index which doesn’t exist in false
Room body contains:

The boolean result of:

is false. If the value of this is in ToAdd then the result of this room would also be a false statement. Even if this shouldn’t logically be the case, it is always worth to check.

is a nil, by your theory it should be false, so it’s fine.

Print out the tables ToAdd and ToUpdate before the final for loop. Without seeing their contents it is hard to guess where things are going wrong.

20:59:09.871 ---------- - Visuals:182

20:59:09.871 Add - {
“Difficulty”:“C”} - Visuals:185
20:59:10.224 1345793720 - Visuals:155

20:59:10.225 Remove - {
“IsPassword”:false} - Visuals:197
20:59:10.225 1345793720 - Visuals:201
20:59:10.225 Removed
20:59:10.225 ---------2 - Visuals:206
20:59:10.225 1 Added - Visuals:208
20:59:10.225 0 Changed - Visuals:209
20:59:10.226 1 Removed - Visuals:210
20:59:10.226 ---------2 - Visuals:211


The object by Remove method is a Node, which is an expected behavior.
And the object by the Add is original RoomData
ToAdd objects are as same as ToUpdate objects

Honestly, I don’t know. You have object oriented structures, but you have made them in a non-standard way. That might be messing things up, but most likely not.

I’m sorry man, but I don’t think I am able to help you. If you are able to find a more concrete source of the issue and require help with that, either ping me in this thread or create a new thread.

Best of luck!

Well turns out that replication was the problem and it was the most of the unexpected ones.
JSON was changing the types of indexes into strings, as I originally used numbers for indexing,
which caused the strange bug.

1 Like