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

DataStore for level saving won't work?

Asked by 7 years ago

Yes, I do have API access enabled.

1local DSS = game:GetService("DataStoreService")
2local leveldatastore = DSS:GetDataStore("LevelNumber")
3 
4game.Players.PlayerAdded:connect(function(player)
5    local level = Instance.new("NumberValue",player)
6    level.Name = "level"
7    level.Value = leveldatastore:GetAsync(player.UserId) or 1
8    leveldatastore:SetAsync(player.UserId,level.Value)
9end)

1 answer

Log in to vote
-1
Answered by 7 years ago
Edited 7 years ago
01local DSS = game:GetService("DataStoreService")
02local leveldatastore = DSS:GetDataStore("LevelNumber")
03game.Players.PlayerAdded:connect(function(player)
04    local PlayerStats = leveldatastore:GetAsync(game.Players[player.Name].UserId)
05    if not PlayerStats then
06        PlayerStats = 1
07        leveldatastore:SetAsync(game.Players[player.Name].UserId, PlayerStats)
08    end
09    local level = Instance.new("IntValue")
10    level.Name = "level"
11    level.Value = PlayerStats
12    level.Parent = game.Players[player.Name]
13end)
0
For future reference with datastores, I recormend https://scriptinghelpers.org/questions/25774 AlphaGamer150 101 — 7y
0
Please explain your code, where he went wrong, and what you did to fix it. awfulszn 394 — 7y
Ad

Answer this question