A All-In-One Roblox instance and datatype serializer
Supports the majority of ROBLOX instances and datatypes.
- This is an early version! Some things may not work as expected. I’m releasing it semi-unfinished because of how long its taking me to complete the rewrite.
What is serialization?
RBXSerialize acts as a solution to, “How can i store obejct in a datastore” or “how can i store leaderstats”. Although this modules somewhat encourages bad habits, the point was making this as a easy and all-in-one solution whilst being compact and fast. To learn more about what seralization is i recommend reading this.
It’s extermely easy to get started using this module.
Ah-ha! Step 1, requiring the module and building the api.
local RBXSerialize = require(game.ReplicatedStorage.Modules.RBXSerialize) RBXSerialize.BuildAPI()
If you dont build the API then the encode methods will fail.
So we got the module. Next step Encoding
local RBXSerialize = require(game.ReplicatedStorage.Modules.RBXSerialize) RBXSerialize.BuildAPI() -- Different Example Values local Model = Instance.new("Model") local Part = Instance.new("Part",Model) local CFrame = CFrame.new(Vector3.new(0,10,35)) local ModelEncoded = RBXSerialize.Encode(Model) local CFrameEncoded = RBXSerialize.Encode(CFrame)
Now our information is stored in a string format. We can use this string to Decode.
local ModelEncoded = RBXSerialize.Encode(Model) local CFrameEncoded = RBXSerialize.Encode(CFrame) -- Theese values are identical to the orginal. You can store the string and recreate it later. local NewModel = RBXSerialize.Decode(ModelEncoded) local NewCFrane = RBXSerialize.Decode(CFrameEncoded)
That’s it! You should now be a pro at decoding and encoding instances using RBXSerialize. Remember that you should save the encoded string to hold on to the instance data.
Things to Note
You can also modify the
NeverSave tables under RBXSerialize to change how the saving works for certain classes.
You can also serialize custom references or references outside of the instance your encoding by using
Here some things you cannot do!
- Have a instance property value with more than 255 Characters.
- Having instance data that exceeds 255 bytes.
- Encode children of a unsupported instance.
Some unique features of RBXSerialize.
- Saves Instance References, Adornee, Parent, and ObjectValue.Value properties.
- Saves Attributes.
- No limitation with instance names.
Here is the latest available version of RBXSerialize.
What does encoded data look like?
This is what raw data looks like for instance data.
*6 instances described in 350bytes.
Will more DataTypes be supported in the future?
Im working on supporting more DataTypes that are needed! If there are any that are not listed in the supported instances. Let me know, and i can add them!
What DataTypes are supported?
- ALL Enums!
Okay? So how big is this thing?
Disclaimer : This references how RAW DATA is stored, data is compressed then put under base92.
Firstly, the default number type is float;
It will only differ if the ROBLOX website specifies something other than “number”
========================= -RBLXSerializer- DataType : 1b -- a header, to tell what type of data it is. -InstanceSeralization- Default Number<FLOAT> : 4b Instance Flat Cost : 1b --[1Byte InstanceName] Property Flat Cost : 3b -- [2 Bytes for the PropertyName][1Byte for Value indicator] Root Flat Cost : 1b -NonInstanceSeralization- Value Flat Cost : 2b -- [1byte for valueName][1Byte for Value indicator] -Example- -- (APPROX) Stings : "My Favorite Folder" ( 10b) -- Strings arent compressed by default! Root Name : "HumanoidRootPart/BodyGyro" (30b) -- working on a better way [Including the entire stringName of all of its children repeated] ========================= -DataTypes- Bool : 1b Faces : 1b Int : 2b Enum : 2b Float : 4b UDim : 8b Double : 8b Vector2 : 8b Vector3 : 12b UDim2 : 16b CFrame : 48b
Small analysis of how data is stored:
Let’s say we have a part with only 2 properties size and position, this is how it would be stored.
It would be stored in as little as 29Bytes.
So I’d say on your average per instance will be 50-100b.
TLDR; Can Serialize pretty much anything! Let’s you store instances in strings to store them in things like datastores !