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

Simple DataStore script keeps returning an error?

Asked by
Yirny 30
8 years ago

My DataStore script isn't working it keep getting an error saying that GetAsync() is not a valid member of datastore?

local datastore = game:GetService("DataStoreService")
game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("IntValue")
    leaderstats.Name = "Stat"
    leaderstats.Parent = player
    local stata = Instance.new("BoolValue")
    stata.Name = "NewPlayer"
    stata.Parent = leaderstats
    local key = "user-" .. player.userId
    local storeditems = datastore:GetAsync(key)
    if storeditems then
        stata.Value = storeditems[1]
    else
        local items = {stata.Value}
        datastore:SetAsync(key, items)
    end
end)
game.Players.PlayerRemoving:connect(function(player)
    local items = {player.Leaderstats.Stat.Value}
    local key = "user-" .. player.userId
    datastore:SetAsync(key, items)
end)

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

I went through the entire script trying to figure out what went wrong and the problem is at the beginning of the script.

On line 1 you defined 'DataStoreService' but you didn't define the DataStore for your game. This can be done with ':GetDataStore()'

Example:

local datastore = game:GetService("DataStoreService"):GetDataStore('GameData')

If you need anymore help feel free to contact me on Roblox. Please check out these links for reference: http://wiki.roblox.com/index.php?title=API:Class/DataStoreService/GetDataStore

http://wiki.roblox.com/index.php?title=API:Class/DataStoreService

0
Oh! Thank you again for your help and I will be sure to ask you on Roblox for help! Yirny 30 — 8y
0
Okay. UniversalDreams 205 — 8y
Ad

Answer this question