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

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

Asked by
Oficcer_F 207 Moderation Voter
5 years ago
Edited 5 years ago

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!

0
im not sure if this will work but when it says points.Value = savedValues[1] make it points.Value = savedValues[1] or 0 stinkyest11 78 — 5y
0
Didn't work... Oficcer_F 207 — 5y
0
It's not recommended to use the 2nd arguement of Instance.new green271 635 — 5y
0
I know. But do you have an answer to my question? Oficcer_F 207 — 5y

1 answer

Log in to vote
1
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
5 years ago

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)
0
My problem is not there. Please look at line 19. Oficcer_F 207 — 5y
0
And, I tried with curly parantheses, but I got the same error at line 19. Oficcer_F 207 — 5y
Ad

Answer this question