Help me redesign this data structure

Hello. I have run into an issue regarding transferring a dictionary of parts to the server.

When I try sending a dictionary (keys being instances, and values being numbers) to the server, the keys get turned into strings. The instance is being loaded on both the server and client, and sending an array of the same instance does not turn the instance reference into a string. I know this is an intentional feature, so I am looking for some workarounds or changes to the data structure.

Down below is an in depth look at my speicifc scenario. I kindly ask that if you are interested, please take a look at what is going on and feel free to ask questions. It might help me out a lot.

Currently, I am trying out a method of bulk-editing different properties for a group of parts. This is how it works.

data = {
    property_data = {
        {
            Transparency = 1
         },

        {
            CanCollide = false
        },
    }

    parts = {
        [PartA] = 1,
        [PartB] = 2,
    }
}

The property_data list holds tables which contain properties and what values they should be set to. Then, the part table contains keys which are equal to part instances, and values which represent the index of the property_data table that will effect the part.

For example, processing this table would make PartA transparent. In parts, PartA is the key, and the value is 1, which is the index of the table that contains the transparency value set to 1.

If you are still confused, please let me know.

What are the benefits of this data structure?

This allows the storage/caching of a list of properties that different parts should have. There can be as many parts as needed, and all of them can be instructed to change a different set of properties to different values. If multiple parts want the same properties to be changed, they can just have their value set to the same index number.

What are the downsides?

The issue this post explains. When I send this data structure through a remote function, all of the instance references turn into strings.
image
image

Unsuccessful Solutions

So far, I have not found any potential solutions that would work out. One idea I have had was to store the parts as an array like this:

parts = {
	{
		part_instance = [PartA],
		property_data_index = 1,
	}
}

The issue, however, is that this seems to be inefficient since many more tables are being used, and much more data is being sent through the remote than necessary.

Conclusion

Since forced string keys are an intentional feature, it would be amazing if you could contribute to my small quest at finding an equally good alternative to this data structure. I am going to bed soon and I have already tried thinking up many solutions that didn’t satisfy me. Though I will work on this tomorrow morning, it would be great if more minds are put into this problem. That is what this category is for after all!

1 Like

What is making you take this route? it might be better to have number/int values as children of these instances and sending an array of instances instead of sending a dictionary.

1 Like

I don’t want to insert and instances or set attributes. I think it is better if the data structure doesn’t require any side effects.

This is because of serialization. When you send a piece of data through a RemoteEvent, it gets converted into JSON data (basically a string, can only have string keys) and then decoded when the other end receives it.

Possible solution: Use the instance names as keys and/or map the instances with their names respectively.

1 Like