Error: Workspace.DataStore:15: attempt to index upvalue 'DSService' (a nil value)
local DSService = game:GetService('DataStoreService'):GetDataStore('StoredData')
game.Players.PlayerAdded:connect(function(plr)
-- Define variables
local uniquekey = "id-"..plr.userId
local stats = Instance.new("Configuration", plr)
local savevalue1 = Instance.new("IntValue",stats)
local savevalue2 = Instance.new("IntValue",stats)
stats.Name = "stats"
savevalue1.Name = "money"
savevalue2.Name = "bananas"
savevalue1.Value = 0
savevalue2.Value = 0
-- GetAsync
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
savevalue1.Value = GetSaved[1]
savevalue2.Value = GetSaved[2]
else
local NumbersForSaving = {savevalue1.Value, savevalue2.Value}
DSService:SetAsync(uniquekey, NumbersForSaving)
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = "id-"..plr.userId
local Savetable = {plr.stats.money.Value, plr.stats.bananas.Value}
DSService:SetAsync(uniquekey, Savetable)
end)
Note: i don't use leaderstats becuse i don't want it to show up on leaderboard!
