Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My DataStore script wont save values! Help?

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

✓ Accepted answer

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"

On line 22, you forgot to include the Value

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

1 comment

0

You should really describe some more if you want more rep lol

This discussion is preserved as it was. New answers, comments, and votes are closed.