Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
2

How would I save leaderstats?

Asked by 3 months ago

I'll make this short, so I am trying to make a currency save system, but it won't work. So If I change "lvl" to 5, next time when I join the game it'll say "0", that means that I have no currency, obviously, no output errors as far as I can see.

local players = game:GetService("Players")
local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("CashValueSaver")

players.PlayerAdded:connect(function(player)
    local folder = Instance.new("Folder")
    folder.Name = "leaderstats"
    folder.Parent = player

    local currency1 = Instance.new("IntValue")
    currency1.Name = "lvl"
    currency1.Parent = player.leaderstats
    currency1.Value = ds1:GetAsync(player.UserId) or 0
    ds1:SetAsync(player.UserId, currency1.Value)

    currency1.Changed:connect(function()
        ds1:SetAsync(player.UserId, currency1.Value)
    end)

    end)

Thanks!

0
Why would you save the data when currency1's value is changed? It would result in a lot of " DataStore request was added to queue" warnings. User#25852 0 — 3mo

2 answers

Log in to vote
2
Answered by 3 months ago

try watching this video https://www.youtube.com/watch?v=5AUP9C0rtBY

0
Instead of just linking OP to a video to have them figure it out themselves, why not try and help them with their issue? User#25852 0 — 3mo
0
how to delete another persons comment botw_legend 452 — 2mo
Ad
Log in to vote
0
Answered by 3 months ago

CashStore = game:GetService("DataStoreService"):GetDataStore("DataStore") function PlayerEntered(player) repeat wait() until player.Character local stats = Instance.new("IntValue") stats.Parent = player stats.Name = "leaderstats" local cash = Instance.new("IntValue") cash.Parent = stats cash.Name = "Cash" if CashStore:GetAsync("Points_"..player.Name) ~= nil then cash.Value = CashStore:GetAsync("Points_"..player.Name) else cash.Value = 500 end cash.Changed:connect(function(Val) CashStore:SetAsync("Points_"..player.Name, Val) end) end game.Players.PlayerAdded:connect(PlayerEntered)

I just wrote a script using the devfourm

Answer this question