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

4 comments

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?

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

0

i believe t[i] is faster than table.insert()

0

@greatneil80 that is a good idea