Remote event weird behavior when passing through hashed table

If you mean Sparse Tables that wasn’t really the case with mine as I was sure I was passing in stringed keys. However, I see what you mean now, thanks for elaborating.

So does this mean that any table I send has to be checked for wrongly set up arrays?

EDIT: I meant deep checks for numerical keys that aren’t in ascending order.

They are not really arrays, just dictionaries with numerical keys (because they are not placed into the array part). But yes, you have to make all similar occurrences of huge numbers as keys into strings.

Realistically you need an abstraction layer for sending data through Remotes, period. You don’t want to have to care about this for every table, you’ll also run into this with userdata keys you’ll frequently want.

Serialize the table yourself, I use {Key = ActualKey, Value = ActualValue} recursively and unpack like that, very simple.

local NetworkUtility = {}

local function GetTableSerialization(Source)
    local Serialization = {}

    for Key, Value in pairs(Source) do
        local KeySerialization = nil

        if type(Key) == "table" then
            KeySerialization = GetTableSerialization(Key)
        else
            KeySerialization = Key
        end

        local ValueSerialization = nil
    
        if type(Value) == "table" then
            ValueSerialization = GetTableSerialization(Value)
        else
            ValueSerialization = Value
        end

        local KeyValuePair = {
            Key = KeySerialization,
            Value = ValueSerialization,
        }
        table.insert(Serialization, KeyValuePair)
    end

    return Serialization
end

function NetworkUtility.GetSerialization(...)
    local Serialization = {}
    local Arguments = {
        ...
    }

    for _, Argument in ipairs(Arguments) do
        local ArgumentSerialization = nil

        if type(Argument) == "table" then
            ArgumentSerialization = GetTableSerialization(Argument)
        else
            ArgumentSerialization = Argument
        end

        table.insert(Serialization, ArgumentSerialization)
    end

    return Serialization
end

local function GetTableUnserialization(Source)
    local Unserialization = {}

    for _, KeyValuePair in ipairs(Source) do
        local Key = KeyValuePair.Key
        local KeyUnserialization = nil

        if type(Key) == "table" then
            KeyUnserialization = GetTableUnserialization(Key)
        else
            KeyUnserialization = Key
        end

        local Value = KeyValuePair.Value
        local ValueUnserialization = nil

        if type(Value) == "table" then
            ValueUnserialization = GetTableUnserialization(Value)
        else
            ValueUnserialization = Value
        end

        Unserialization[KeyUnserialization] = ValueUnserialization
    end

    return Unserialization
end

function NetworkUtility.GetUnserialization(Serialization)
    local Unserialization = {}

    for _, Argument in ipairs(Serialization) do
        local ArgumentUnserialization = nil

        if type(Argument) == "table" then
            ArgumentUnserialization = GetTableUnserialization(Argument)
        else
            ArgumentUnserialization = Argument
        end

        table.insert(Unserialization, ArgumentUnserialization)
    end

    return Unserialization
end

return NetworkUtility
1 Like