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

How can I use data stores correctly?

Asked by
mnaj22 44
9 years ago
local DataStore = game:GetService("DataStoreService"):GetDataStore("mnaj22 level")


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

    Level = player.PlayerGui.ScreenGui.Value

    local key = "player-" ..player.userId

    local savedValues = DataStore:GetAsync(key)

    if savedValues then
        Level.value = savedValues(1)
    else
        local valuesToSave = (Level)
        DataStore:SetAsync(key, valuesToSave)
    end
end)
0
17:16:27.671 - Workspace.Script:14: attempt to call local 'savedValues' (a number value) 17:16:27.681 - Stack Begin 17:16:27.682 - Script 'Workspace.Script', Line 14 17:16:27.683 - Stack End mnaj22 44 — 9y

2 answers

Log in to vote
1
Answered by
saenae 318 Moderation Voter
9 years ago

I'm not well-versed with data stores as yet, so I know I'm not the most qualified to answer this question -- but no one else is doing so. From looking at it (and checking the wiki a bit), it doesn't look as if your problem is in using the storage itself, but that you're setting your 'Level.value' to 'savedValues(1)' rather than just 'savedValues'. Not sure if I'm just misreading it.

0
Yes, the parenthesis indicate he's trying to call a function from a number, that would break the script each time. He'll need to remove the (1). M39a9am3R 3210 — 9y
Ad
Log in to vote
0
Answered by 9 years ago
local DataStore = game:GetService("DataStoreService"):GetDataStore("mnaj22 level")


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

    Level = player.PlayerGui.ScreenGui.Value

    local key = "player-" ..player.userId

    local savedValues = DataStore:GetAsync(key)

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

Few syntax mistakes. When you want to access a member of a table, use square brackets [] not parentheses ().

Answer this question