Guide
TypeCoercer
Serialize Roblox types to string and reconstruct them. Useful when you need to send Roblox-specific values through routes or store them in DataStore.
When to use this. Route payloads and DataStore only support plain Lua types. TypeCoercer lets you pass a
Vector3 or CFrame by encoding it as a string, then decode it back on the other side.Basic round-trip
local TC = RoExpress("TypeCoercer")
local v = Vector3.new(10, 5, 3)
local s = TC.ToString(v) -- "10,5,3"
local ok, r = TC.FromString(s, "vector3") -- true, Vector3.new(10, 5, 3)
print(ok, r == v) -- true true
Sending a CFrame over a route
-- client: encode before sending
network:Post("char/position", {
cframe = TC.ToString(char:GetPivot()) -- "x,y,z,rx,ry,rz"
})
-- server: decode in handler
app:Post("char/position", function(Player, Payload, req, res)
local ok, cf = TC.FromString(req.data.cframe, "cframe")
if ok then
-- cf is a CFrame
end
end)
Instances
To serialize an Instance reference, register a named root so TypeCoercer can search for it by ClassName and Name.
TC.RegisterInstanceRoot("Workspace", workspace) -- server & client
TC.RegisterInstanceRoot("Players", game:GetService("Players"))
local part = workspace:FindFirstChild("Baseplate")
local str = TC.ToString(part) -- "Part:Baseplate"
local ok, back = TC.FromString(str, "Instance") -- the Baseplate Part
Wire format. All types are encoded as comma-delimited values with no type prefix.
ToString always produces a plain string; FromString requires the expected type name so it knows how to parse it.Supported types
| Roblox type | Wire format |
|---|---|
| Vector3 | x,y,z |
| Vector2 | x,y |
| CFrame | x,y,z,rx,ry,rz (position + Euler angles in degrees) |
| Color3 | r,g,b (0–255 integers) |
| UDim2 | xs,xo,ys,yo |
| UDim | scale,offset |
| Rect | minX,minY,maxX,maxY |
| Instance | ClassName:Name (searches registered roots) |
| EnumItem | Enum.TypeName.ValueName |
| number, string, boolean, int | Passed through as plain string |
See also
Types | Luau type definitions · Codec | binary serialization for high-frequency data · Stream Guide | typed channels that bypass this entirely