Table Manipulation - Question

I’m trying to add a table with a variable dependent name, but the table keeps getting overwritten.

Code:

local ServerPlacementData = {}

function ServerHouseCreatorHandler:CreatePart(ClientData,PartData)
   local PartIdentifier = HttpService:GenerateGUID(false)
   ServerPlacementData[ClientData] = {["PlacedParts"] = {}}
   ServerPlacementData[ClientData].PlacedParts[PartIdentifier] = {PartData[1],PartData[2],PartData[3],PartData[4],PartData[5]}
end

Result is that the created table (PartIdentifier) will keep on getting overwritten as the function keeps on being used.

I’m trying to achieve something like this:

local ServerPlacementData = {
   ["39520489"] = {
      ["1B1B424B-ACBF-4C4F-8BEE-DADFE80E1EED"] = {
         PartData[1],PartData[2],PartData[3],PartData[4],PartData[5]
      }
   }
}

It’s because you keep resetting it with this line here:
ServerPlacementData[ClientData] = {[“PlacedParts”] = {}}

I think what you’d want is a check first, then you’d do that only if it doesn’t already exist. That way you can keep all the past data

1 Like

Thanks for that :slight_smile:

(oof, quite embarassed for not seeing that)

2 Likes