Need Suggestions on how to keep track of Nodes on the server

Basically, I am trying to keep track of every Node on the server
I made a big DB that keeps track of every Node (an Basepart) with a respective NodeID

What I tried:

local NodeDatabase = {} --Current used Nodes

function NodeHandler:new() --DO NOT FORGET: Node is a table
	--Node Template
	local Node = setmetatable({	
		NodeID = tonumber(#NodeDatabase + 1), --ID gets set to the last index of the table + 1 (so ID is the same as the Node index in the DB)
		NodeRarity = nil,
		NodeDurability = nil,
		NodePosition = nil
	}, self)
	table.insert(NodeDatabase, Node)
	return Node
end

As you can see here, I tried to make an ID system in which the ID will correspond to the index of the Node in the DB (i.e ID = index in the DB)

I was going to make an attribute and set the ID to NodeID, so I associate the Node in the DB to the Node in workspace

ISSUE:
I soon realized that not only its going to be terrible for performance bc everytime I will destroy/add a node, I will have to update every single node in the DB using a for loop, but it can cause other issues like DB data corruption (if two methods run at once, etc.)

Do yall suggestions on how I can track each unique workspace Nodes on the server or any way to assign a unique ID to each Node without having to update every single change on DB

Thank you

Use HTTPService:GenerateGUID(), seems like the best way to create a unique ID.

and to assign it to a physical Node (Instance on workspace) do I make an attribute and set its value to the ID?

if yes, is there a way to “hide” an attribute so it doesnt appear in the property tab or whats the best way to associate a workspace instance to the unique id

Why would you want to set an attribute in the first place? What’s the use case?

to associate a Node on the workspace (a physical node) to a Node object on the DB

i.e I will be able to track changes on the workspace Node on the server (DB)

and I need a way to “associate” them

Use a dictionary with the index set to the node in workspace and the value being the nodes data? Or you can also add a another index in your node data named Node and set it to the node in workspace? I’m saying all this because attributes are replicated to all clients and though they aren’t as bad as value bases, they still aren’t optimal.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.