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)
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!