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

DataStore not working?[unsolved]

Asked by 9 years ago
01datastore = game:GetService("DataStoreService"):GetDataStore("FarmStatsCJ")
02 
03local function set(key,value)
04        datastore:SetAsync(key,value)
05end
06 
07local function get(key)
08    datastore:GetAsync(key)
09end
10 
11game.Players.PlayerRemoving:connect(function(player)
12    wait(1)
13    local l = player.leaderstats
14    set('leaderstatsFarmCJ1'..player.userId,l.Money)
15    set('leaderstatsFarmCJ2'..player.userId,l.level)
View all 42 lines...

The datastore doesn't work, and since I've never used datastore before, I don't know what i did wrong.

1 answer

Log in to vote
1
Answered by
einsteinK 145
9 years ago
  1. What if the player doesn't have saved data yet? Doing get('idk') would return nil. Doing Money.Value = nil isn't very good.

  2. Why don't you make the leaderstats/inv/... in that script too? Then you don't have to wait.

  3. Why do you wait(1) on PlayerRemoving? The server might shutdown before you can save.

  4. Instead of saving every stat in a separate key, why not put it all in one table?

01-- Saving
02local stats = {}
03stats.Money = Money.Value
04stats.Role = Role.Value
05set("Data_"..play.userId,stats)
06-- Loading
07local stats = get("Data_"..play.userId)
08if not stats then return end -- NO STATS, USE DEFAULT
09Money.Value = stats.Money
10Role.Value = stats.Role
0
thank you. the consept of what this is helped me ScriptsAhoy 202 — 9y
Ad

Answer this question