Saving cash and rebirths

I am new to scripting , So I am new in Saving Players Cash Value and Rebirth (I am not asking for script but for some help)

Use Datastores. Here is an example:

local ds = game:GetService("DataStoreService")
local CashData = ds:GetDataStore("CashData") --Can change "CashData" to anything.

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
    local Cash = Instance.new("IntValue")
    Cash.Name = "Cash"
    Cash.Parent = leaderstats
    Cash.Value = CashData:GetAsync(player.UserId) or 0
end)

game.Players.PlayerRemoving:Connect(function(player)
    CashData:SetAsync(player.UserId, player.leaderstats.Cash.Value)
end)

game:BindToClose:Connect(function()
    for i,v in pairs(game.Players:GetPlayers()) do
        CashData:SetAsync(v.UserId, v.leaderstats.Cash.Value)
    end
end)

https://www.youtube.com/channel/UCp1R0TBvgM7gj0rwTYULmSA go through this he is best he made many tutorials

1 Like

Please do some research and learn some APIs before making this topic. Don’t just straight away ask how to do this without learning thieves thing yet.

I’m so sorry I am new and needed desperate help…

ok thank you for helping me out

Use DataStores to save your data for players, if you look into this API Reference:

You should probably see examples of using the different functions, which will help you understand more.


Also because you are new, just saying, try to put your new replies in one post itself.

1 Like

I won’t recommend you give out whole scripts like that as Devforum isn’t for giving whole scripts out… It also contains a few bad practices, and the OP hasn’t asked for it either.

2 Likes

Ok ThankYou @WaterJamesPlough

I don’t recommend using SetAsync to save data, data loss may occur more often

Then please, learn the basics of scripting first. Don’t just straight away create the topic. Learn some tutorials first.

I know Basics (not too advanced) but This Feels Advanced to me I’m new…

Yea you should use data stores for this problem as many people have said. There is a community tutorial on the DevForum here that is very useful: Datastore Tutorial for Beginners

There are also videos on youtube explaining datastore by people like @Alvin_Blox, @UseCode_Tap, and @Peaspod.

3 Likes

I would recommend that you watch tutorials and type manually to better understand

1 Like

ok thankyou I am gonna do that for sure…As Its highly recommended thankyou for helping

If you think it’s advanced, I can guranteed that you didn’t learn well the basics yet.

1 Like

Yes I used SetAsync But My Values dont stay the same…What should i do