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

Attempt to index local 'savedValues' (a number value)? [DATA STORE]

Why doesn't my data store script work?

Here it is:

DataStore = game:GetService("DataStoreService"):GetDataStore("PeasStore")


game.Players.PlayerAdded:connect(function(player)

local stats = Instance.new("IntValue", player)
stats.Name = "leaderstats" 

local points = Instance.new("IntValue", stats)
points.Name = "Points" 

local coins = Instance.new("IntValue", stats)
coins.Name = "Coins" 

local key = ("player-" .. player.UserId)
local savedValues = DataStore:GetAsync(key)

if savedValues then
	points.Value = savedValues[1]
	coins.Value = savedValues[2]
else
	local valuesToSave = (points.Value)
	DataStore:SetAsync(key, valuesToSave)
	
	
	
	
	
end

end)

Error at line 19!

4 comments

0

im not sure if this will work but when it says points.Value = savedValues[1] make it points.Value = savedValues[1] or 0

0

Didn't work...

0

It's not recommended to use the 2nd arguement of Instance.new

0

I know. But do you have an answer to my question?

1 answer

✓ Accepted answer

Because you're not actually saving it in a table, you're just saving the points' value by itself because you have normal parantheses, instead of curly parantheses used to construct a table.

local valuesToSave = {points.Value}
DataStore:SetAsync(key, valuesToSave)

2 comments

0

My problem is not there. Please look at line 19.

0

And, I tried with curly parantheses, but I got the same error at line 19.

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