I've been experimenting with the Datastore in ROBLOX recently. After huge amounts of tests over the years, I'm sometimes greeted with ROBLOX unable to process my query due to the servers being down or something.
This is currently what I use;
1 | pcall ( function () |
2 | local test = serviceDatastore:GetDataStore( 'test' ) |
3 |
4 | if test:GetAsync( 'test' ) = = 'yum' then -- if the value to the key is yum then we know the datastore is working because it's returned 'yum' |
5 | return true |
6 | else |
7 | return false |
8 | end |
9 | end ) |
Is there a more efficient way to do this? Thanks!
01 | local success, message = pcall ( function () |
02 | local test = serviceDatastore:GetDataStore( 'test' ) |
03 |
04 | if test:GetAsync( "test" ) = = "yum" then |
05 | return true |
06 | else |
07 | return false |
08 | end |
09 | end ) |
10 |
11 | if success then |
12 | --code here |
13 | else |
14 | print ( "An error occurred: " .. message) |
15 | end |
You use pcall to check that the block of code will work, else we will do other things or do something else to fix that.