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 = require(game.ReplicatedStorage.RoExpress.TypeCoercer)

local v = Vector3.new(10, 5, 3)
local s = TC.ToString(v)       -- "Vector3|10|5|3"
local r = TC.FromString(s)     -- Vector3.new(10, 5, 3)
print(r == v)                    -- true

Sending a CFrame over a route

-- client: encode before sending
network:Post("char/position", {
    cframe = TC.ToString(char:GetPivot())
})

-- server: decode in handler
app:Post("char/position", function(Player, Payload, req, res)
    local cf = TC.FromString(req.data.cframe)
    -- cf is a CFrame
end)

Instances

To serialize an Instance reference, register the root first so TypeCoercer can resolve paths.

TC.RegisterInstanceRoot(game)     -- server
TC.RegisterInstanceRoot(game)     -- client

local part = workspace:FindFirstChild("Baseplate")
local str  = TC.ToString(part)    -- "Instance|Workspace.Baseplate"
local back = TC.FromString(str)   -- the Baseplate Part

Supported types

Roblox typeEncoded prefix
Vector3Vector3|x|y|z
Vector2Vector2|x|y
CFrameCFrame|x|y|z|r00…r22
Color3Color3|r|g|b
UDim2UDim2|xs|xo|ys|yo
UDimUDim|scale|offset
RectRect|minX|minY|maxX|maxY
InstanceInstance|full.path
number, string, booleanPassed through unchanged

See also

Types | Luau type definitions  ·  Codec | binary serialization for high-frequency data  ·  Stream Guide | typed channels that bypass this entirely