Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How would I save leaderstats?

Asked by 4 years 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.

01local players = game:GetService("Players")
02local datastore = game:GetService("DataStoreService")
03local ds1 = datastore:GetDataStore("CashValueSaver")
04 
05players.PlayerAdded:connect(function(player)
06    local folder = Instance.new("Folder")
07    folder.Name = "leaderstats"
08    folder.Parent = player
09 
10    local currency1 = Instance.new("IntValue")
11    currency1.Name = "lvl"
12    currency1.Parent = player.leaderstats
13    currency1.Value = ds1:GetAsync(player.UserId) or 0
14    ds1:SetAsync(player.UserId, currency1.Value)
15 
16    currency1.Changed:connect(function()
17        ds1:SetAsync(player.UserId, currency1.Value)
18    end)
19 
20    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 — 4y

2 answers

Log in to vote
2
Answered by 4 years 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 — 4y
0
how to delete another persons comment botw_legend 502 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
01CashStore = game:GetService("DataStoreService"):GetDataStore("DataStore")
02function PlayerEntered(player)
03    repeat wait() until player.Character
04 
05    local stats = Instance.new("IntValue")
06    stats.Parent = player
07    stats.Name = "leaderstats"
08 
09    local cash = Instance.new("IntValue")
10    cash.Parent = stats
11    cash.Name = "Cash"
12 
13    if CashStore:GetAsync("Points_"..player.Name) ~= nil then
14        cash.Value = CashStore:GetAsync("Points_"..player.Name)
15    else
View all 23 lines...

I just wrote a script using the devfourm

Answer this question