Inside of my data storage script, I want to add more values. For example, there is a value called "Cash" inside of a value called Levelss. I'd like to add another value, the same exact way that Cash is added, but every time I do, something went wrong. I'm still very new to Data Storage. Any ideas?
local DSService = game:GetService('DataStoreService'):GetDataStore('DataStoreName')
game.Players.PlayerAdded:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Levelss = Instance.new('IntValue', plr)
local savevalue = Instance.new('IntValue')
Levelss.Name = 'Levelss'
savevalue.Parent = Levelss
savevalue.Name = 'Cash'
-- GetAsync
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
savevalue.Value = GetSaved[1]
else
local NumbersForSaving = {savevalue.Value}
DSService:SetAsync(uniquekey, NumbersForSaving)
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.Levelss.Cash.Value}
DSService:SetAsync(uniquekey, Savetable)
end)

1 comment
What value are you trying to add and what's the error?