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

Simple DataStore script keeps returning an error?

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

✓ Accepted answer

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

2 comments

0

Oh! Thank you again for your help and I will be sure to ask you on Roblox for help!

0

Okay.

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