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

My DataStore script wont save values! Help?

Asked by 7 years ago
Edited 7 years ago

I made this datastore script but it wont save my data!

local LevelDataStore = game:GetService("DataStoreService"):GetDataStore('Level')

game.Players.PlayerAdded:connect(function(Player)
local key = 'id-'..Player.userId
local leaderstats = Instance.new("IntValue", Player)
local exp = Instance.new("IntValue", leaderstats)
leaderstats.Name = "leaderstats"
exp.Name = "EXP"

local SaveAsync = LevelDataStore:GetAsync(key)
if SaveAsync then
    exp.Value = SaveAsync[1]
else
    local ThingsToSave = {exp.Value}
    LevelDataStore:GetAsync(key, ThingsToSave)
end
end)


game.Players.PlayerRemoving:connect(function(Player)
    local key = 'id-'..Player.userId
    local SaveTable = {Player.leaderstats.EXP}
    LevelDataStore:SetAsync(key, SaveTable)
end)

2 answers

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

On line 22, you're replacing the value of EXP everytime the player leaves with the EXP itself, and not the value that he EXP has.

local SaveTable = {Player.leaderstats.EXP.} --You did 

Just do...

local SaveTable = {Player.leaderstats.EXP.Value} --"EXP.Value"
Ad
Log in to vote
1
Answered by
npott13 23
7 years ago

On line 22, you forgot to include the Value

local SaveTable = {Player.leaderstats.EXP.Value}

0
You should really describe some more if you want more rep lol Abstract_Life 65 — 7y

Answer this question