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

Need help storing values in a table?

I am trying to store values in a table and save and load them, but they aren't saving, I am calling the module from a script in serverscriptservice, and I have api services enabled, and there are no errors, if anyone can help that'd be great

Code:

local data = {}

local datastore = game:GetService("DataStoreService"):GetDataStore("RPG 1")

function data.load(plr)
	local key = plr.UserId
	local stats = Instance.new("Folder", plr)
	stats.Name = "Stats"
	
	local level = Instance.new("NumberValue", stats)
	level.Name = "Level"
	level.Value = 1
	
	local currentExp = Instance.new("NumberValue", stats)
	currentExp.Name = "CurrentExp"
	currentExp.Value = 0
	
	local maxExp = Instance.new("NumberValue", stats)
	maxExp.Name = "MaxExp"
	maxExp.Value = 250
	
	local gold = Instance.new("NumberValue", stats)
	gold.Name = "Gold"
	gold.Value = 100
	
	local values = {level.Value, currentExp.Value, maxExp.Value, gold.Value}
	
	local savedValues = datastore:GetAsync(key, values)
	
	if savedValues ~= nil then
		values = savedValues
	end
	
end

function data.save(plr)
	local key = plr.UserId
	local values = {plr.Stats.Level.Value, plr.Stats.CurrentExp.Value, plr.Stats.MaxExp.Value, plr.Stats.Gold.Value}
	datastore:SetAsync(key, values)
end

return data

2 comments

0

Errors?

0

There are no errors

1 answer

Your issue is that you are using another argument for GetAsync, that argument is totally irrelevant.

local savedValues = datastore:GetAsync(key, values)
if savedValues then values = savedValues end

1 comment

0

I tried without it but it didn't save

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