Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Error with DataStore. Help?

Asked by 10 years ago

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!

0
I think you have an unnecessary space in line 13. Remove the space after the two dots, so it would be ..player.userId SlickPwner 534 — 10y

2 answers

Log in to vote
2
Answered by 10 years ago

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.

0
oh wow...it was that simple and stupid of a mistake...Thanks! ImmenseKassing 120 — 10y
Ad
Log in to vote
0
Answered by
Merely 2122 Moderation Voter Community Moderator
10 years ago

The method is named GetAsync, not getAsync

Edit: Same applies to SetAsync

Answer this question