So If
local S,E = pcall(function() return DataStore:GetAsync('DataKey') end)
S returns true or false and E returns the Data that was saved
But I noticed that for SetAsync its different
local S,E = pcall(function() return SetAsync('DataKey',Value) end)
E dosent return anything it returns nil does anyone know what this E is meant to be for
I assume you know how pcalls work but it never hurts to go through it again:
local a, b, c = pcall(function() return 1 - "three", 20 end) print(a, b, c) --> false input:2: attempt to perform arithmetic on a string value nil
So in case of an error in the body we can observe that: 1. The first variable - a - becomes false, meaning success of the pcall was false
The second variable - b - becomes a string with the error that occured in the pcalls body
All other variables which would normally get a returned value were nil, no values have been returned
local a, b, c = pcall(function() return 1 *3, 1 + 3 end) print(a, b, c) --> true 3 4
This time we can see that:
The first variable shows the body ran successfully
b- which was previously the error string - is now the first returned value and c is the second
Your problem is that
return datastore:SetAsync(...)
Is as good as doing
return nil
Why? It's since the datastore:SetAsync() method returns no value at all. Hence the variable E which is the value returned by the body, is nil.