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

Leveling System, Why isn't my Data Saving?

Asked by 6 years ago

Making a custom leveling system Errors: None Whats wrong: Data is not saving Things to know: FE is turned on. And this is a serverscript

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")
local Lvl = DataStore:GetDataStore("Level")
local XPS = DataStore:GetDataStore("XP")

game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder",player)
leader.Name = "Stats"
local Cash = Instance.new("IntValue",leader)
local XPNeeded = Instance.new("IntValue",leader)
XPNeeded.Name = "XPNeeded"
local Level = Instance.new("NumberValue",leader)
Level.Name = "Level"
Cash.Name = "XP"
Cash.Value = ds:GetAsync(player.UserId) or 0
ds:SetAsync(player.UserId, Cash.Value)
Lvl:SetAsync(player.UserId, Level.Value)
XPS:SetAsync(player.UserId, XPNeeded.Value)
XPNeeded.Value = Cash.Value * 500 *1.75
Cash.Changed:connect(function()
    if Cash.Value >= XPNeeded.Value then
        Cash.Value = 0
        XPNeeded.Value = Cash.Value * 150 * 1.75
        Level.Value = Level.Value +1
        Lvl:SetAsync(player.UserId, Level.Value)
        XPS:SetAsync(player.UserId, XPNeeded.Value)
    end
ds:SetAsync(player.UserId, Cash.Value)
end)
end)


game.Players.PlayerRemoving:connect(function(player)
ds:SetAsync(player.UserId, player.Stats.XP.Value)
Lvl:SetAsync(player.UserId, player.Stats.Level.Value)
XPS:SetAsync(player.UserId, player.Stats.XPNeeded.Value)
end)

2 answers

Log in to vote
0
Answered by 6 years ago

Try to enable in Configure Place the Place API and Save API and then it would save

0
Didn't work Bryson467 12 — 6y
0
make sure its enabled in Configure Game aswell DarkWQlfc 20 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Because when the player joins, you're setting the data stores to the intvalue's value (which is 0 since the player just joined and hasn't earnt anything). Don't use setasync when the player joins, and don't use it when the value changes (since there's a limit to how many times you can set a datastores value). Instead do it in intervals (like every 2 minutes) and when the player leaves or the server closes.

tl;dr: remove lines 16, 17 and 18.

Answer this question