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

What does SetAsync second parameter return in pcall?

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

1 answer

I assume you know how pcalls work but it never hurts to go through it again:

When the pcall works but it's body has errored


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

  2. The second variable - b - becomes a string with the error that occured in the pcalls body

  3. All other variables which would normally get a returned value were nil, no values have been returned

When the pcalls body runs safely


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:

  1. The first variable shows the body ran successfully

  2. b- which was previously the error string - is now the first returned value and c is the second

Your problem


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.

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