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

What is Async's. Why are they useful, and what are they all about?

Hello again, I see alot in scripting called Async. I know many people use it in DataStore, but I can't find so much resources to what Async is. Does someone here link me some resourcces, and what Async is useful, and what it's about.

Thank you,

Ducksneedhelp

1 comment

0

Async means Asynchronous, not A synchronise. Basically chronous means time, and sync means sequence. So, basically it yields (stops) until it sets the data and A means not.

1 answer

✓ Accepted answer

In DataStorageService, SetAsync() is to save Data and GetAsync() is to Load Data.

Example of a simple saving and loading-data-system:

local dataStorage = game:GetService("DataStoreService")
local CoinsData = dataStorage:GetDataStore("CoinsData")

game.Players.PlayerAdded:Connect(
    function(player) -- when player joins
        local leaderstats = Instance.new("Folder")
        leaderstats.Name = "leaderstats"
        leaderstats.Parent = player

        local Coins = Instance.new("IntValue") 
       Coins.Name = "Coins" -- change to whatever
        Coins.Parent = leaderstats
        Coins.Value = CoinsData:GetAsync(player.UserId) or 0 -- loading their data or if no data found, giving 0 coins
        Coins.Changed:Connect(
            function() -- when their coin value changes
                Coins:SetAsync(player.UserId, Energy.Value)
            end
        )
    end
)

More information: https://developer.roblox.com/en-us/api-reference/function/GlobalDataStore/GetAsync and https://developer.roblox.com/en-us/api-reference/function/GlobalDataStore/SetAsync

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