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

DatatStore Failed Fetching Stats, why?

Asked by
BryanFehr 133
5 years ago

Hello! I am creating a currency system used in my Club Game, Club Void, and I was wondering as to why I am getting the failure to fetch print on my output? The error it brings is "GetASync is NOT a valid member of Global Data"

Here is an image of the failed output: https://gyazo.com/d23d2e045cc79e143a626e9c4f4d6033 Here is my code:

local dss = game:GetService("DataStoreService")
local mydatastore = dss:GetDataStore("mydatastore")

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    local vcash = Instance.new("IntValue")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
    vcash.Name = "VCash"
    vcash.Parent = leaderstats

    local data
    local success, errormessage = pcall(function()
        data = mydatastore:GetASync(player.UserId.."-VCash")
    end)
    if success then
        vcash.Value = data
    else
        print("Error Fetching Data!")
        warn(errormessage)
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    local success,  errormessage = pcall(function()
        mydatastore:SetASync(player.UserId.."-VCash",player.leaderstats.vcash.Value)
    end)
    if success then
        print("Stats Saved!")
    else
        print ("Saving Failed!")
        warn(errormessage)
    end
end)


0
Okay I edited script for you, it should work. B_rnz 171 — 5y

1 answer

Log in to vote
1
Answered by
B_rnz 171
5 years ago
Edited 5 years ago

Your code should be spelled correctly, but it's a common error most scripters make.

You were doing 'GetASync' and 'SetASync' and not 'GetAsync' and 'SetAsync'

Line 14 should be:

data = mydatastore:GetAsync(player.UserId.."-VCash")

and Line 26 Should be:

-- because vcash isnt a valid member of folder, so you change it to VCash
mydatastore:SetAsync(player.UserId.."-VCash",player.leaderstats.VCash.Value)

Also, if you want the value to change/save do not change it through explorer but in the script so you'd add something like in PlayerAdded:

vcash.Value = vcash.Value + 100

Hope this works!

0
I typed this, replaced that silly mistake, and it still doesn't save my stats. Would there be another reason as to why this isn't functioning? BryanFehr 133 — 5y
0
Oh okay I get it, lemme edit it B_rnz 171 — 5y
0
Awesome, this worked. Thanks for showing me my silly mistakes, LOL. BryanFehr 133 — 5y
0
No problem :D B_rnz 171 — 5y
Ad

Answer this question