How to Add a Table to a DataStore Table?

I’m trying to save a table called “PartData” to a DataStore Key called “PlacedParts” in the defined DataStore, but I cannot get around overwritting the previous data. I’m currently using DataStore:SetAsync(“PlacedParts”, Part Data)

local PlacedPartsDataStore = DataStoreService:GetDataStore("PLACED_PARTS_TEST", "CLIENT_" .. Client.UserId)

The Data I want to save

local PartData = {
		[UniqueIdentifier] = {

I think it has to do with the number indexes, “Data[1]”.
Try converting the number indexes to strings. For example, [“1”] or [“whatevernameyouwant”].

The “Data” table is a table coming from the player passed via RemoteEvent, so the Data[1], Data[2] etc have values

But you can’t convert them to strings? Send [“1”] over [1]? From what I remember, I don’t think it’s possible to send number tables to DataStores…

Try this?

local PartData = {
		[UniqueIdentifier] = {
			["1"] = Data[1],
			["2"] = Data[2],
			["3"] = Data[3],
			["4"] = Data[4],
			["5"] = Data[5]

PartData.UniqueIdentifier.1 or PartData.UniqueIdentifier[“1”]

The data still gets overwritten :neutral_face:

What I meant was

Player Places A Part
Invoke RemoteServer with Part Data (Position, Rotation, Material, etc)
Server Receives Part Data
Server Saves Part Data

Ohhh my bad I misread it, if you don’t cache data, you would want to grab the data, and put the unique data inside the data, and save that all together. (You want to add the data to the existing data right?) (Sorry if I’m confused)

I appologise as well on my part if my post wasn’t as clear

I’m trying to achieve this:


But I keep on getting this:

(The first result keeps on overwritting to the next part placed)

1 Like

Given you’re trying to add an array to an existing array. It’s as simple as the example provided below.

local Tb = {
	Currency = {Coins = 0, Gems = 0},
	Inventory = {}
Tb.Misc = {} --Creates an array called 'Misc" in 'Tb'

If this isn’t the case. You weren’t providing enough information in your OP for me to assist.


This is actually close to what I need :slight_smile:
Thanks a lot :heart:

1 Like