I need some datastore help, Does anyone know how to save new Table data without the need to change datastore?, For Example, If i make a datastore and add Coins for example and join the game, The player data is created, But if i add Gems and Levels later the data is set to 0 heres my code
local Webhook = require(script.Webhook)
local DatstoreService = game:GetService('DataStoreService')
local Datastore = DatstoreService:GetDataStore('PlayerData-TESTA0005')
function module.SetUp(plr)
local playervalues = game.ServerStorage.Values:Clone()
local name = plr.Name
local userid = plr.UserId
local key = userid..'-'
local default = {Money=500, Karma=50}
local data
for _, values in pairs(playervalues:GetChildren()) do
data = values
end
local success, ret = pcall(Datastore.GetAsync, Datastore, key)
if success then
if ret then
data.Value = ret[data.Name]
else
data.Value = default[data.Name]
end
else Webhook.Request(plr, 'Datastore API', 'Datastore:GetAsync() Failed to Retrieved DatastoreKey: '..key)
end
playervalues.Parent = plr
end
this part piratically
if ret then
data.Value = ret[data.Name]
else
data.Value = default[data.Name]
end
ret is basically getAsync(), if ret is saying if i have Data then load in ret[data]
But since i have the If ret it means it will only work if data already exist, Basically saying if i add new data it doesnt load because data already exist so it wont set the values for it does anyone know how to fix this?, Heres my PlayerLeaving Event
function module.Save(plr)
local playervalues = plr:FindFirstChild('Values')
local name = plr.Name
local userid = plr.UserId
local key = userid..'-'
local data = {}
if playervalues then
for _, values in pairs(playervalues:GetChildren()) do
data[values.Name] = values.Value
end
local success, ret = pcall(Datastore.SetAsync, Datastore, key, data)
if success then
print('Successfully Saved DatastoreKey: '..key)
else Webhook.Request(plr, 'Datastore API', 'Datastore:SetAsync() Failed to Retrieve DatastoreKey: '..key)
end
end
end
Sorry i cant really explain it well heres an easier way to explain it, If i have gold and levels it loads the data for it, But if i add new stuff after data doesnt load for the new stuff, only works if i change the datastore, Someone help ;-;