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.

local DSS = game:GetService("DataStoreService")
local leveldatastore = DSS:GetDataStore("LevelNumber")

game.Players.PlayerAdded:connect(function(player)
    local level = Instance.new("NumberValue",player)
    level.Name = "level"
    level.Value = leveldatastore:GetAsync(player.UserId) or 1
    leveldatastore:SetAsync(player.UserId,level.Value)
end)

1 answer

Log in to vote
-1
Answered by 7 years ago
Edited 7 years ago
local DSS = game:GetService("DataStoreService")
local leveldatastore = DSS:GetDataStore("LevelNumber")
game.Players.PlayerAdded:connect(function(player)
    local PlayerStats = leveldatastore:GetAsync(game.Players[player.Name].UserId)
    if not PlayerStats then
        PlayerStats = 1
        leveldatastore:SetAsync(game.Players[player.Name].UserId, PlayerStats)
    end
    local level = Instance.new("IntValue")
    level.Name = "level"
    level.Value = PlayerStats
    level.Parent = game.Players[player.Name]
end)
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