Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

DatatStore Failed Fetching Stats, why?

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)


1 comment

0

Okay I edited script for you, it should work.

1 answer

✓ Accepted answer

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!

4 comments

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?

0

Oh okay I get it, lemme edit it

0

Awesome, this worked. Thanks for showing me my silly mistakes, LOL.

0

No problem :D

This discussion is preserved as it was. New answers, comments, and votes are closed.