My datastore values are being replaced and they don’t get added
local DataStoreService = game:GetService("DataStoreService")
local playerDataStore = DataStoreService:GetDataStore("PlayerDataStore")
local sellOrdersDataStore = DataStoreService:GetDataStore("SellOrders")
local function saveSellOrder(player, sellOrderRobotName, sellOrderPrice)
local key = "R_" .. sellOrderRobotName
local success, sellOrder = pcall(function()
sellOrdersDataStore:UpdateAsync(key, function(sellOrders)
print(sellOrders)
if sellOrders == nil then
sellOrders = {}
end
table.insert(sellOrders, {
SellOrderPlayer = player.UserId,
SellOrderPrice = sellOrderPrice
})
return sellOrders
end)
end)
local success, currentSellOrder = pcall(function()
return sellOrdersDataStore:GetAsync(key)
end)
if success then
print(currentSellOrder)
end
end
workspace.Robot1Part.ClickDetector.MouseClick:Connect(function(player)
saveSellOrder(player, workspace.Robot1Part.Name, math.random(10, 20))
end)
workspace.Robot2Part.ClickDetector.MouseClick:Connect(function(player)
saveSellOrder(player, workspace.Robot2Part.Name, math.random(50, 100))
end)
workspace.Robot3Part.ClickDetector.MouseClick:Connect(function(player)
saveSellOrder(player, workspace.Robot3Part.Name, math.random(200, 500))
end)
When I print the key the first time it will print 2 values
When I click another part it will still only print 2 different values