Data stores
OrderedDataStores can only store positive numbers
500
25000
2138912
1
-599
'my string'
false or true
Instance.new('Part')
{table}
This data store is mostly used for Leaderboards (Like top 100 best gamers) because it has access to function :GetSortedAsync(), this function will return specified amount of keys stored in the data store sorted from lowest to highest or highest to lowest (You can customize it all in there).
The normal DataStore can save any userdata
true or false
'my string'
5000
-5000
{table}
Instance.new('Part')
{dictionary}
So this would be used for saving user's data. If i am sure dictionaries are not allowed to be saved in data store but i don't know what a dictionary is :/.. i can surely tell tho that for example this type of table can be saved in the data store for sure:
SetAsync( {
money = 50000,
cash = 93184194,
something = true,
} )
Pcalls
Pcalls (Private Calls) are used to catch errors, they run given function and if it errors then it stops the function, that way you can be sure that if the fucntion errors, your script won't break, example:
local function MyFunction()
local MyVariable = 5 + 'MyString'
end
pcall(MyFunction)
When this will be run, no errors would be shown because the pcall detected the error inside the function and stopped the function, it returns 2 arguments
Success - Whether the function errored or not
Error - Returns error as a string if the function errored, otherwise nil
So in this case the return would be
local function MyFunction()
local MyVariable = 5 + 'MyString'
end
local Success, Response = pcall(MyFunction)
print(Success, Response)
xpcall is same as pcall but it accepts second argument which is Callback, this argument is a function which will run if the first function in argument 1 errors
local function MyFunction()
local MyVariable = 5 + 'MyString'
end
local function Callback(Error)
print( string.format('Oh no! Something bad happened!: %s', Error) )
end
xpcall(MyFunction, Error)
Oh no! Something bad happened!: Attempt to compensate number and string
Useful Sources:
Datastore v GlobalDataStore
Lua globals
Scripting Helpers - How does pcall, xpcall, and ypcall actually work?
Pcall - Pil
1 comment
This question has been answered effectively before, use the search feature!