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
RoomNodeClass.LoadRoom(RoomObject,RoomNode,ScrollingFrame)
print(RoomObject.HostId) 153th line
end
module.RemoveRoom = function(RoomNodeClass)
RoomNodeClass.Remove()
Rooms[RoomNodeClass.Host] = nil
end
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
else
ToUpdate[RoomId] = Room
end
end
local Added = 0
local Changed = 0
local Removed = 0
for RoomId,Room in pairs(ToAdd) do
print(RoomId) 183th line
module.AddRoom(Room)
Added += 1
end
for RoomId,Room in pairs(ToUpdate) do
Rooms[RoomId].UpdateRoom()
Changed += 1
end
for RoomId,Room in pairs(Rooms) do
if ToAdd[RoomId] or ToUpdate[RoomId] then
continue
end
module.RemoveRoom(Room)
Removed += 1
end
print(Added,"Added")
print(Changed,"Changed")
print(Removed,"Removed")
end
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.
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?
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
module.RemoveRoom(Room)
Removed += 1
end
end
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:
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.
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.
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.
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.