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

What is SetASync and GetASync?

I'm learning datastore and I'm confused on this? What do they do? How do I use them? Another thing is. When do I use ds = game:GetService("DataStore")?

2 answers

✓ Accepted answer

DataStore is a new feature that some developers are starting to get into. They can save a simple string or number value and can be used server to server without a player even ever having to enter the server to open the data.

:GetDataStore(String), even though you didn't ask I thought this would be important to go over, you're basically setting up or using a like subsection of DataStore, that way you can have like a Kills Data Store and a WipeOuts DataStore

:SetAsync(String, Value) will save the text or number value. Under the Name of the value and the value itself.

ds = game:GetService("DataStore"):GetDataStore("Test")
ds:SetAsync("KOs_" .. tostring(player.userId), player.Kills.Value)
--The code would save Knock out by userId

:GetAsync(String) will load up the value set from SetAsync.

ds = game:GetService("DataStore"):GetDataStore("Test")
if ds:GetAsync("KOs_" .. tostring(player.userId)) ~= nil then
player.Kills.Value = ds:GetAsync("KOs_" .. tostring(player.userId))
else
player.Kills.Value = 0
end
--The code will see if previous data exists, if it does then the data store loads it, if not then the value is 0.

These are the basics I have learned, and probably be the basics I will live with. If you have any questions I might help if you just leave a comment, or consult this page from the wiki.

2 comments

1

Is there a way to do a global chat between all servers? And thank you for this message. When I just save a number do I need to call ds? I have this: credits.Value = LoadNumber("credits_"..script.Parent.Parent.UserId)

1

You need to call for DataStore when you want to Set or Get a Async. It is possible to make a chat system between multiple servers, although it might require a loop to change the chats whenever someone says something.

Oh, SetAsync() is to save Data in DataStoreService and GetAsync() is to Load Data.

Calling DataStore(Defining):

Let's say I where to save a person data when they leave.

ds = game:GetService("DataStoreService")
datastore ds:GetDataStore("PlrData")
game.Players.PlayerRemoving:connect(function(plr)
 z = plr:WaitForChild("leaderboard")
x = z:GetChildren()
for i  = 1, #x do
datastore:SetAsync(x[i].Name,x[i].Value)

end


end)


Hope this helped

+1 id this helped :)

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