DataStores, It's for saving stuff, you already know. But I'll show you how to use it!
GetDataStore
This is the most important thing when using DataStores(Other than the DataStoreService)
local data = game:GetService("DataStoreService"):GetDataStore("Test")
One DataStore can have multiple keys.
GetAsync
This get's the value for the key
local data = game:GetService("DataStoreService"):GetDataStore("Test")
print("The Brick's color is: "..data:GetAsync("Color"))
SetAsync
It gives or changed the key's value.
local data = game:GetService("DataStoreService"):GetDataStore("Test")
data:SetAsync("Color", "Red")
print("The Brick's color is: "..data:GetAsync("Color"))
data:SetAsync("Color", "Blue")
print("The Brick's color is: "..data:GetAsync("Color"))
UpgradeAsync
Some people say this should be used more than SetAsync. It does almost the same thing as SetAsync but it is in a form of a function.
local data = game:GetService("DataStoreService"):GetDataStore("Test")
data:UpgradeAsync("Points", function(old)
local new = old or 0
new = new+10
return new
end)
data:UpgradeAsync("Points", function(old)
return 50
end)
IncrementAsync
####Increments the value for a particular key and returns the incremented value. Only works on values that are integers.
--Wiki
local data = game:GetService("DataStoreService"):GetDataStore("Test")
data:IncrementAsync("Number", 1)
I've never used IncrementAsync so ask someone like BlueTaslem, Goulstem, Redbullusa, adark, etc.
DataPersistance
Should not be used because DataStores is better. DataStores can save within universes. DataPersistance does not.
Save/Load Numbers, Strings, Booleans, Instance
Can only be saved and loaded from a player.
local player = game:GetService("Players").LocalPlayer
print(player.Name.." had this many points: "..player:LoadNumber("Points"))
player:SaveNumber("Points", 50)
print("Now the player has "..player:LoadNumber("Points").." points!")
Tables, Arrays, Pairs
Tables is a list of strings, numbers, bools, and objects:
Table = {}
Table2 = {"Hai", "Hello", "Wassup", 21, true, false, 54, workspace.Part:clone(), ":3"}
table.insert(Table, "Hello", 1)
Arrays are very similar:
Array = {"Hello", 23}
Array2 = {
{thing = "Hello"}
{no = "false"}
}
Array3 = {Hi = 2, No = false, Error = "5/0"}
Pairs works by...
for i,v in pairs(table) do
end
Hope this helps!
1 comment
I hate it when people ninja me! I will keep mine up still though, since he asked help for DataStores, Pairs, and also maybe some data persistance.