This is my DataStore. Like any other DataStore, it is supposed to save leaderstats. For whatever reason, it is not doing that. Why? Here is my code:
local DSService = game:GetService('DataStoreService'):GetDataStore('LeaderstatDataStore')
game.Players.PlayerAdded:connect(function(plr)
local uniquekey = 'id-'..plr.UserId
local leaderstats = Instance.new ('IntValue', plr)
local savevalue = Instance.new ('IntValue')
leaderstats.Name = 'leaderstats'
savevalue.Parent = leaderstats
savevalue.Name = 'Subscribers'
local savevalue2 = Instance.new ('IntValue')
savevalue2.Parent = leaderstats
savevalue2.Name = 'Views'
local savevalue3 = Instance.new ('IntValue')
savevalue3.Parent = leaderstats
savevalue3.Name = 'Videos'
local savevalue4 = Instance.new ('IntValue')
savevalue4.Parent = leaderstats
savevalue4.Name = 'Money'
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
savevalue.Value = GetSaved [1]
savevalue2.Value = GetSaved [1]
savevalue3.Value = GetSaved [1]
savevalue4.Value = GetSaved [1]
else
local NumbersForSaving = {savevalue.Value, savevalue2.Value, savevalue3.Value, savevalue4.Value}
DSService:SetAsync(uniquekey, NumbersForSaving)
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.UserId
local Savetable = {plr.leaderstats.Subscribers.Value, plr.leaderstats.Views.Value, plr.leaderstats.Videos.Value, plr.leaderstats.Money.Value}
DSService:SetAsync(uniquekey, Savetable)
end)
