Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I optimize my serialization code?

Asked by 3 years ago

I have created a block building game, it saves when the player leave but the serialization isn't quick enough. The player leaves before serialization is complete. Here's what I have so far:

function serializeData(object)
    --Object is the input for the thing you want to save
    local bedrock = game.Workspace:FindFirstChild("StartIsland"):FindFirstChild("Bedrock").Bedrock.Position
    local data = {}
    for _,model in ipairs(object:GetChildren()) do
        --Holder
        local dataHolder = {}
        --Pack Data
        local primaryPart = model.PrimaryPart
        local position = primaryPart.Position
        local direction = primaryPart.CFrame.lookVector
        --Save Data to data list
        dataHolder.ModelName = model.Name
        dataHolder.Position = {position.X - bedrock.X, position.Y - bedrock.Y, position.Z - bedrock.Z, direction.X, direction.Y, direction.Z}
        table.insert(data, dataHolder)
    end
    --Return data
    return data
end

I have tried to optimize it as much as possible but the for loop isn't quick enough, it doesn't save anything until its ALL done

0
why dont you make it so whenever a player clicks a button ui called Save it fires a remote event to the server, the server adds a cooldown using os.time or tick, and it saves the player data? CaioAlpaca 342 — 3y
0
You can store their names in a linked table with their data which you can easily retrieve in seconds right as the user leaves greatneil80 2647 — 3y
0
i believe t[i] is faster than table.insert() zadobyte 692 — 3y
0
@greatneil80 that is a good idea deadwalker601 110 — 3y

Answer this question