I am currently using a UUID system as pointers in a structure system I am working on. I am using raycasts to determine the inputs and outputs of the specified structure and need a way to access the hit structure’s UUID. The current and easiest way I can think of is to put a stringValue instance in the model which can be used to reference the structure it is associated with.
The problem I am having is determining whether this system would be secure or not. I don’t want hackers to use the UUID to maliciously mess with other structures by making false requests to the server to access said structure’s data. Is the usage of a string value the best way to handle this? Would there be a better solution for structures to get another structures UUID?
To elaborate, you should have two hashmaps (dictionaries); one is UUID → Instance, and the other is Instance → UUID. This allows you to easily convert between strings and the instance they represent.
Here’s some pseudocode example:
local toInstance: {[string]: Instance} = {}
local toUUID: {[Instance]: string} = {}
local function registerInstance(i: Instance): string
local UUID: string = newUUID()
toInstance[UUID] = i
toUUID[i] = UUID
-- To prevent memory leaks, make sure to deregister the instance when it's
-- destroyed or it will stay on memory forever!
i.AncestryChanged:Connect(function()
if not i:IsDescendantOf(game) then
toInstance[UUID] = nil
toUUID[i] = nil
end
end)
return UUID
end
local part = workspace:WaitForChild('Part')
local id = registerInstance(part)
-- To convert between UUID and instance, simply index the corresponding hashmap.
-- It will automatically default to nil if missing
print('the ID of the part is', toUUID[part])
print('the owner of the ID is', toInstance[id])