GetAsync is not a valid member of DataStoreService

Hello i keep getting this error " GetAsync is not a valid member of DataStoreService." I am very new to data stores and i dont know what im doing wrong. Can someone help me?

script:

local DataStore = game:GetService("DataStoreService")
local Level1 = DataStore:GetDataStore("Level001")
local Exp1 = DataStore:GetDataStore("Exp001")
local MaxHealth1 = DataStore:GetDataStore("DefenseP001")
local Strength1 = DataStore:GetDataStore("Strength001")
local Stamina1 = DataStore:GetDataStore("Stamina001")
local Spins1 = DataStore:GetDataStore("Spins001")
local Yen1 = DataStore:GetDataStore("Yen001")
local Points1 = DataStore:GetDataStore("Points001")
local ExpNeed1 = DataStore:GetDataStore("ExpNeed001")
local Quirk1 = DataStore:GetDataStore("Quirk001")
local Fame1 = DataStore:GetDataStore("Fame001")


game.Players.PlayerAdded:Connect(function(Plr)
	local stats = Instance.new("Folder", Plr)
	stats.Name = "Stats"
	--- Level System
	local Level = Instance.new("NumberValue", stats)
	Level.Name = "Level"
	Level.Value = 1
	
	local Exp = Instance.new("NumberValue", stats)
	Exp.Name = "Exp"
	Exp.Value = 0
	
	local ExpNeed = Instance.new("IntValue", stats)
	ExpNeed.Name = "ExpNeed"
	ExpNeed.Value = 100
	
	--- Money and Spin System
	local Yen = Instance.new("IntValue", stats)
	Yen.Name = "Yen"
	Yen.Value = 0
	
	local Spins = Instance.new("NumberValue", stats)
	Spins.Name = "Spins"
	Spins.Value = 5	
	
	--- Stats System
	local Points = Instance.new("NumberValue", stats)
	Points.Name = "Points"
	Points.Value = 3
	
	local MaxHealth = Instance.new("IntValue", stats)
	MaxHealth.Name = "MaxHealth"
	MaxHealth.Value = 100
	
	local Stamina = Instance.new("IntValue", stats)
	Stamina.Name = "Stamina"
	Stamina.Value = 0
	
	local Quirk = Instance.new("StringValue", game.StarterGui.Values)
	Quirk.Name = "Abillity"
	Quirk.Value = "Quirkless"
	
	--- Fame
	local leaderstats = Instance.new("Folder",Plr)
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = Plr
	
	local Fame = Instance.new("IntValue")
	Fame.Name = "Fame"
	Fame.Value = 0
	Fame.Parent = leaderstats
	
spawn(function()		
		
	wait(4)		
		
	local StaminaBarMax = Instance.new("IntValue",stats)		
	StaminaBarMax.Name = "AbilityStaminaMax"	
	StaminaBarMax.Value =  100 + (Plr.Stats.Stamina.Value*5)			
		
	local StaminaBar = Instance.new("IntValue",stats)	
	StaminaBar.Name = "AbilityStamina"	
	StaminaBar.Value = StaminaBarMax.Value		
end)
	
	local Strength = Instance.new("IntValue", stats)
	Strength.Name = "Strength"
	Strength.Value = 0
	
	
	local playerdata = {
		Fame = Fame.Value,
		Quirk = Quirk.Value,
		Stamina = Stamina.Value,
		MaxHealth = MaxHealth.Value,
		Points = Points.Value,
		Spins = Spins.Value,
		Yen = Yen.Value,
		ExpNeed = ExpNeed.Value,
		Exp = Exp.Value,
		Level = Level.Value	
	}
	
	
	local Data = DataStore:GetAsync(playerdata)
	local data = DataStore:GetAsync(Plr.UserId)
	
	
	
		while true do
		wait(30)
		for _, player in pairs(game.Players:GetPlayers())do		
			DataStore:SetAsync(player.UserId, playerdata)
			print("Saved")
			end
		end
	end)
2 Likes

You’re calling GetAsync on DataStoreService instead of on one of your data stores. You can only call GetAsync on one of these:

Level1
Exp1
MaxHealth1
Strength1
Stamina1
Spins1
Yen1
Points1
ExpNeed1
Quirk1
Fame1

1 Like

Times like these the dev API reference is really usefull. Here is an example script I found for using GetAsync within this article:

local DataStoreService = game:GetService("DataStoreService")
local experienceStore = DataStoreService:GetDataStore("PlayerExperience")
 
local success, currentExperience = pcall(function()
	return experienceStore:GetAsync("Player_1234")
end)
 
if success then
	print("Current Experience:", currentExperience)
end

now lets compare this with yours:

yeah basically its the same as what @ND_B7 said, but I recommend comparing your code with the dev api reference first.

1 Like

Thank you and also what would be “player experience” in my case? Exp.Value?

The name of your data store. That is just a code sample by the way so you should modify it to your needs.

1 Like

Is their a way to Use UpdateAsyc in one table so i take up less requests?

1 Like

Just save one table under one key instead of using like 20 different datastores for one player’s data.

3 Likes

Try this script.

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("PlayerData")


game.Players.PlayerAdded:Connect(function(Plr)
	local stats = Instance.new("Folder", Plr)
	stats.Name = "Stats"
	--- Level System
	local Level = Instance.new("NumberValue", stats)
	Level.Name = "Level"
	Level.Value = 1
	
	local Exp = Instance.new("NumberValue", stats)
	Exp.Name = "Exp"
	Exp.Value = 0
	
	local ExpNeed = Instance.new("IntValue", stats)
	ExpNeed.Name = "ExpNeed"
	ExpNeed.Value = 100
	
	--- Money and Spin System
	local Yen = Instance.new("IntValue", stats)
	Yen.Name = "Yen"
	Yen.Value = 0
	
	local Spins = Instance.new("NumberValue", stats)
	Spins.Name = "Spins"
	Spins.Value = 5	
	
	--- Stats System
	local Points = Instance.new("NumberValue", stats)
	Points.Name = "Points"
	Points.Value = 3
	
	local MaxHealth = Instance.new("IntValue", stats)
	MaxHealth.Name = "MaxHealth"
	MaxHealth.Value = 100
	
	local Stamina = Instance.new("IntValue", stats)
	Stamina.Name = "Stamina"
	Stamina.Value = 0
	
	local Quirk = Instance.new("StringValue", game.StarterGui.Values)
	Quirk.Name = "Abillity"
	Quirk.Value = "Quirkless"
	
	--- Fame
	local leaderstats = Instance.new("Folder",Plr)
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = Plr
	
	local Fame = Instance.new("IntValue")
	Fame.Name = "Fame"
	Fame.Value = 0
	Fame.Parent = leaderstats
	
spawn(function()		
		
	wait(4)		
		
	local StaminaBarMax = Instance.new("IntValue",stats)		
	StaminaBarMax.Name = "AbilityStaminaMax"	
	StaminaBarMax.Value =  100 + (Plr.Stats.Stamina.Value*5)			
		
	local StaminaBar = Instance.new("IntValue",stats)	
	StaminaBar.Name = "AbilityStamina"	
	StaminaBar.Value = StaminaBarMax.Value		
end)
	
	local Strength = Instance.new("IntValue", stats)
	Strength.Name = "Strength"
	Strength.Value = 0
	
	
	local playerdata = {
		Fame = Fame.Value,
		Quirk = Quirk.Value,
		Stamina = Stamina.Value,
		MaxHealth = MaxHealth.Value,
		Points = Points.Value,
		Spins = Spins.Value,
		Yen = Yen.Value,
		ExpNeed = ExpNeed.Value,
		Exp = Exp.Value,
		Level = Level.Value	
	}
	
	
	local Data = DataStore:GetAsync(Plr.UserId)
	if Data then
		playerdata.Fame = Data.Fame
		playerdata.Quirk = Data.Quirk
		playerdata.Stamina = Data.Stamina
		playerdata.MaxHealth = Data.MaxHealth
		playerdata.Points = Data.Points
		playerdata.Spins = Data.Spins
		playerdata.Yen = Data.Yen
		playerdata.ExpNeed = Data.ExpNeed
		playerdata.Exp = Data.Exp
		playerdata.Level = Data.Level
	end

		Fame.Value = playerdata.Fame
		Quirk.Value = playerdata.Quirk
		Stamina.Value = playerdata.Stamina
		MaxHealth.Value = playerdata.MaxHealth
		Points.Value = playerdata.Points
		Spins.Value = playerdata.Spins
		Yen.Value = playerdata.Yen
		ExpNeed.Value = playerdata.ExpNeed
		Exp.Value = playerdata.Exp
		Level.Value = playerdata.Level
		
		while wait(30) do
			playerdata.Fame = Fame.Value
			playerdata.Quirk = Quirk.Value
			playerdata.Stamina = Stamina.Value
			playerdata.MaxHealth = MaxHealth.Value
			playerdata.Points = Points.Value
			playerdata.Spins = Spins.Value
			playerdata.Yen = Yen.Value
			playerdata.ExpNeed = ExpNeed.Value
			playerdata.Exp = Exp.Value
			playerdata.Level = Level.Value
			DataStore:SetAsync(Plr.UserId, playerdata)
		end
		
	end)
5 Likes

Thanks for the script, ima study this and learn it but i want to know how to do it, but thanks a lot!

2 Likes

No problem! If my script was able to solve your issue, please mark it as the solution.

One more question, my data wont save on exit? is it too much to save at once?

game.Players.PlayerRemoving:Connect(function(player)
		playerdata.Fame = Fame.Value
		playerdata.Quirk = Quirk.Value
		playerdata.Stamina = Stamina.Value
		playerdata.MaxHealth = MaxHealth.Value
		playerdata.Points = Points.Value
		playerdata.Spins = Spins.Value
		playerdata.Yen = Yen.Value
		playerdata.ExpNeed = ExpNeed.Value
		playerdata.Exp = Exp.Value
		playerdata.Level = Level.Value
		playerdata.Strength = Strength.Value
		local success, errormessage = pcall(function()
			DataStore:SetAsync(Plr.UserId, playerdata)
		end)
		
		if success then
			print("DataSaved")
		else
			print("Data Failed To Save")
			warn(errormessage)
		end
		
	end)

btw i put a print command right under the pcall, before the data store and it printed, but nothing after prints

It’s because you declared all of your variables in a different scope. You need to do this:

game.Players.PlayerRemoving:Connect(function(player)
		local playerdata = {}
		local Fame = player.leaderstats.Fame
		local stats = player.Stats
		local Quirk = stats.Abillity
		local Stamina = stats.Stamina
		local MaxHealth = stats.MaxHealth
		local Points = stats.Points
		local Spins = stats.Spins
		local Yen = stats.Yen
		local ExpNeed = stats.ExpNeed
		local Exp = stats.Exp
		local Level = stats.Level
		local Strength = stats.Strength

		playerdata.Fame = Fame.Value
		playerdata.Quirk = Quirk.Value
		playerdata.Stamina = Stamina.Value
		playerdata.MaxHealth = MaxHealth.Value
		playerdata.Points = Points.Value
		playerdata.Spins = Spins.Value
		playerdata.Yen = Yen.Value
		playerdata.ExpNeed = ExpNeed.Value
		playerdata.Exp = Exp.Value
		playerdata.Level = Level.Value
		playerdata.Strength = Strength.Value
		local success, errormessage = pcall(function()
			DataStore:SetAsync(Plr.UserId, playerdata)
		end)
		
		if success then
			print("DataSaved")
		else
			print("Data Failed To Save")
			warn(errormessage)
		end
		
	end)

im having the same problem still wont save

well it seems to work sometimes, idk sometimes it doesnt work. It doesnt error, it just doesnt get to the pcall and saving sometimes

sorr y it gets to the pecall everytime, just not the setAsync

Did you accidentally put the PlayerRemoving inside of the PlayerAdded event? Make sure they’re separate and one isn’t inside the other. Also make sure Studio Access to API Services is enabled. Data Stores can also be pretty buggy in Studio, so try publishing and testing in an actual server.

1 Like

Does it only happen in studio? Because studio API services aren’t the greatest

1 Like

it seems like its only in the studio

Try using a BindToClose function so that the server has time to save as the server closes.

2 Likes