local DS = game:GetService('DataStoreService')
local MSD = DS:GetDataStore('MSD')
game.Players.PlayerAdded:Connect(function(plr)
local stats = Instance.new("BoolValue",plr)
stats.Name = "leaderstats"
local Cash = Instance.new("IntValue",stats)
Cash.Name = "Cash"
Cash.Value = 1020
local cps = Instance.new('IntValue', stats)
cps.Name = "CPS"
local data
local data2
local success, errormessage = pcall(function()
data = MSD:GetAsync(plr.UserId..'-Cash')
data2 = MSD:GetAsync(plr.UserId..'-CPS')
end)
if success then
Cash.Value = data
cps.Value = data2
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errormessage = pcall(function()
MSD:SetAsync(plr.UserId..'-Cash', plr.leaderstats.Cash.Value..'-CPS', plr.leaderstats.CPS.Value)
end)
if success then
print('Data successfully saved')
else
print('There was an error saving data')
warn(errormessage)
end
end)
local DSService = game:GetService('DataStoreService'):GetDataStore('') --Change this name to a random name or it will not workgame. 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 = 'Points' 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.leaderstats.Points.Value} DSService:SetAsync(uniquekey, Savetable) end)