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

Line 21: Attempt to index local 'savedvalue' (a number value)? [Needs resolving]

Asked by 9 years ago
local datastore = game:GetService("DataStoreService"):GetDataStore("rP")
local serverstorage = game:GetService("ServerStorage")
game.Players.PlayerAdded:connect(function(plyr)
    local rp = Instance.new("IntValue")
    rp.Parent = serverstorage
    rp.Name = "rP-"..plyr.Name
    local key = "plyr"..plyr.userId
    local username = Instance.new("StringValue")
    username.Parent = serverstorage
    username.Name = plyr.Name
    username.Value = plyr.Name

    local userid = Instance.new("IntValue")
    userid.Parent = serverstorage
    userid.Name = plyr.Name.."-id"
    userid.Value = plyr.userId

    local savedvalue = datastore:GetAsync(key)

    if savedvalue then
        rp.Value = savedvalue[1]
        username.Value = savedvalue[2]
        userid.Value = savedvalue[3]
    else
        datastore:SetAsync(key, rp.Value, username.Value,userid.Value)
    end
end)

This is my code. I can't figure out why it cannot index savedvalue.

Any input?

1 answer

Log in to vote
0
Answered by
SurVur 86
9 years ago

You seem to be saving a tuple, however, you are trying to access it like you would a table. I'll rewrite line 25 datastore:SetAsync(key, {rp.Value, username.Value, userid.Value})

0
This doesn't fix it. I'm still getting the same error. dirty_catheter 7 — 9y
0
Oh wait, I think that this might be because sometimes DataStore will make the number be something like 10.0000000001. Since IntValues can't use decimals, try using math.floor() to round it down SurVur 86 — 9y
Ad

Answer this question