Hi! I want to make a DataStore saving and setting script, so I just put it along inside the leaderstats script. This was my first time doing it by myself, and I thought it was too… easy. Nothing is wrong with it in game, I just feel like theres a protection or something like that to add. Heres the script:
local dss = game:GetService("DataStoreService")
local moneyDss = dss:GetOrderedDataStore("Money")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"
local latestStage = Instance.new("IntValue", plr)
latestStage.Name = "latestStage"
local stage = Instance.new("IntValue", leaderstats)
stage.Name = "Stage"
local money = Instance.new("IntValue", leaderstats)
money.Name = "Money"
local moneyAmt = moneyDss:GetAsync(plr.UserId)
money.Value = moneyAmt
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, err = pcall(function()
moneyDss:SetAsync(plr.UserId, plr.leaderstats.Money.Value)
end)
if success then
print("Player Stats Saved Successfully!")
else
warn(err)
end
end)
So yeah, thats the script. Just setting it and saving it. No big deal to me.