local Datastoreser = game:GetService("DataStoreService")
local DataStore = Datastoreser:GetDataStore("Clans")
local NewClan = {"RyClan", 1, 2000, 5}
DataStore:SetAsync()
print(DataStore:GetAsync("Clans"))
so i want to make it so you can save it into a table in a datastore (i already saved a table with the key “Clans”) but if i save a value, it saves too but if someone from another server saves it at the same time, only 1 will save.
How can i fix this?
You are setting data with the same key, thats why it won’t work. Also I recommend using pcalls to ensure it doesn’t break while saving data as DataStores can fail (userId is the player’s userId
local Clans
local success, errorMsg = pcall(function()
Clans = DataStore:GetAsync("Clans_"..userId)
end)
if success then
table.insert(Clans, NewClan)
else warn(errorMsg) end
local success1, errorMsg1 = pcall(function()
DataStore:SetAsync("Clans_"..userId, Clans)
end)
if success1 then
print(Clans)
else warn(errorMsg1) end