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

What does :GetAsync("User-"..player.UserId) mean in Roblox?

Asked by
2mania 14
2 years ago
Edited 2 years ago

Hi Im trying to break down this script that I found on youtube and im confused about one part and its this part GetAsync("User-"..player.UserId) could someone please also explain what "Waters" is equal

here is the full script if you need it

local DataStoreService = game:GetService("DataStoreService")
local collected = DataStoreService:GetDataStore("collected")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local WaterList = ReplicatedStorage:WaitForChild("Waterbottles")

game.Players.PlayerAdded:Connect(function(player)
    local WaterCollected = Instance.new("Folder",player)
    WaterCollected.Name = "WaterGettingColder"
    local success, errormessage = pcall(function()
        local water = collected:GetAsync("User-"..player.UserId)
        if water then
            for i, v in pairs(water) do
                local waterfound = WaterList:FindFirstChild(v)
                if waterfound then
                    waterfound:Clone().Parent = WaterCollected
                end
            end
        end
    end)
end)

game.Players.PlayerRemoving:Connect(function(player)
    local success, errormessage = pcall(function()
        local collectedsave = {}
        for i, waters in pairs(player.WatereCollect:GetChildren()) do
            if waters then
                table.insert(collectedsave,waters.Name)
            end
        end
        collected:SetAsync("User-"..player.UserId,collectedsave)
    end)
end)


game:BindToClose(function(player)
    local success, errormessage = pcall(function()
        local collectedsave = {}
        for i, waters in pairs(player.WatereCollect:GetChildren()) do
            if waters then
                table.insert(collectedsave,waters.Name)
            end
        end
        collected:SetAsync("User-"..player.UserId,collectedsave)
    end)
end)
0
GetAsync gets data from the datastore, so basically it retrieves the data. The string inside "GetAsync" is what file is being retrieved. SetAsync sets the data so that next time when you join, GetAsync will get that data. greatneil80 2647 — 2y

2 answers

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

:GetAsync is something that saves your entire progress, It is important for some games which wanted to make sure you have same value as your past value after you leave or took a break and change 'em and this thing will save up as your past value or current value. As result, your data saved in Datastore will saved unless it resets by renaming string or adding number in.

Adding Datastore be like this:

local number = 1
local datastore = game:GetService("DataStoreService")

local data = datastore:GetDataStore("Test", number)

(Sorry, if this isn't problem you are facing)

Ad
Log in to vote
0
Answered by
lrd14 0
2 years ago

:GetAsync is to do with getting a value like "Money" from a dataStore on Roblox. A dataStore is what saves data and basically lets you bring all your data on other games in your experience!

A example of this can be shown as:

local n = 1 --// Number
local ds = game:GetService("DataStoreService") --// DataStore
local result = ds:GetDataStore("D", n)

You can then use the data from the var "result". Hope this helps!

Answer this question