You want to use DataStoreService to save your values.
Now the way you organize your datastores is up to you and everyone has different ways of doing it. You could create two datastores, one for money and one for rebirth. Or, you could use one datastore which stores a dictionary of both values. This is what I'll be doing in my example.
local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("MoneyRebirthDS")
local emptyData = {
["Money"] = 0,
["Rebirth"] = 0
}
game.Players.PlayerAdded:Connect(function(player)
local success, data = pcall(function()
return playerData:GetAsync(player.UserId)
end)
if success then
data = data or emptyData
local playerMoney = data["Money"]
local playerRebirth = data["Rebirth"]
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local newData = {
["Money"] = player.Money
["Rebirth"] = player.Rebirth
}
local success, errorMessage = pcall(function()
playerData:SetAsync(player.UserId, newData)
end)
if not success then
print(errorMessage)
end
end)
I haven't tested the script so I don't know if it works perfectly or not, but those are the basic elements you need in a data saving system. Some people prefer to also save every few minutes or so, incase the game crashes and the data fails to save when the player leaves. Read up on DataStoreService, Roblox gives us a lot of documentation on it for us to learn everything about it. Let me know if you have any other questions!
1 comment
Thank you! So I did everything you said but it still did not for some reason. I wondered if maybe it was because the script I wrote for keeping track of the leaderstats was making a new folder each time you enter a server so maybe that is the problem to why it keeps going back to zero?? I would show you my leaderstats script but I don't know how