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

My datastore is not working? I have no errors?

Asked by 7 years ago

I have 3 values, Gold EXP Level, none of them are saving?!?!?!?

I get no errors!

Help!

local DataStore = game:GetService("DataStoreService")
local Usersave = DataStore:GetDataStore("UserSaver")


game.Players.PlayerAdded:connect(function(plr)
    local key = "player-" ..plr.userId 

    local stat = Instance.new("IntValue", plr)
    stat.Name = "leaderstats"
    --Gold
    local Gold = Instance.new("IntValue", stat)
    Gold.Name = "Gold"
    Gold.Value = 0
    --EXP
    local EXP = Instance.new("IntValue", stat)
    EXP.Name = "EXP"
    EXP.Value = 0
    --Level
    local Level = Instance.new("IntValue", stat)
    Level.Name = "Level"
    Level.Value = 0

    EXP.Changed:connect(function()
        Level.Value = math.floor(EXP.Value/1000 * math.random(1, 5))
    end)

    local GetSaved = Usersave:GetAsync(key)
    if GetSaved ~= nil then
        local SavingValues = {Gold.Value, EXP.Value, Level.Value}
        Usersave:SetAsync(key, SavingValues)
        print("Data found!")
    elseif GetSaved ~= nil then
        print("data wasn't found!")
        local SavingValues2 = {Gold.Value, EXP.Value, Level.Value}
        Usersave:SetAsync(key, SavingValues2)


    end



end)
game.Players.PlayerRemoving:connect(function(plr)
    print("saving data!")
local key = "player-"..plr.userId

local ValuesToSave = {plr.leaderstats.EXP.Value, plr.leaderstats.Level.Value, plr.leaderstats.Gold.Value}
Usersave:SetAsync(key, ValuesToSave)

end)



1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

on line 28-38 you messed up(on both of the conditions you asked if GetSaved ~= nil) you also did this(which sets the key to 0 again) but i dont know what you are trying to do

local SavingValues = {Gold.Value, EXP.Value, Level.Value}
Usersave:SetAsync(key, SavingValues)

fix:

if GetSaved then
    local SavingValues = {Gold.Value, EXP.Value, Level.Value}
    Usersave:SetAsync(key, SavingValues)
    print("Data found!")
else
    print("data wasn't found!")
    local SavingValues2 = {Gold.Value, EXP.Value, Level.Value}
Usersave:SetAsync(key, SavingValues2)
end

Ad

Answer this question