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

Error with DataStore. Help?

So, I'm trying to make a leaderboard where it displays the level of a player using the script below:

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

game.Players.PlayerAdded:connect(function(player)
	local leaderstats = Instance.new("IntValue", player)
	leaderstats.Name = "leaderstats"
	
	local levelstats = Instance.new("IntValue", leaderstats)
	levelstats.Name = "Level"
	
	local key = "user_" .. player.userId
	player.leaderstats.Level.Value = DataStore:getAsnyc(key)
	if DataStore:getAsnyc(key) == 0 then
		DataStore:setAsync(key, 1)
		local connection = DataStore:OnUpdate(key, function(value)
			player.leaderstats.levelstats.Value = DataStore:getAsnyc(key)
		end)
	end
end)

Whenever I run it, I get this error: 16:32:21.444 - getAsnyc is not a valid member of GlobalDataStore 16:32:21.445 - Script 'Workspace.Leaderstats', Line 13

What's wrong with the script? I have found no reason why getAsnyc would not work for DataStore. Please help me!

1 comment

0

I think you have an unnecessary space in line 13. Remove the space after the two dots, so it would be ..player.userId

2 answers

✓ Accepted answer

Check the spelling of "GetAsync"

It's Async, not Asnyc.

"Async" is short for "Asynchronous" which means the function will yield the thread until it receives the data.

1 comment

0

oh wow...it was that simple and stupid of a mistake...Thanks!

The method is named GetAsync, not getAsync

Edit: Same applies to SetAsync

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