A question about declaring a pcall() variable

I have a question about declaring a pcall() function
so when we use declare it, the code pretty looks like this

local data
local success, response = pcall(function()
    data = DataStore:GetAsync("key")
end)

but at the line,

local success, response = pcall(function()
    data = DataStore:GetAsync("key")
end)

it is like declaring 2 variable at once like

local a, b = 1, 2

now back to the previous code, it looks like i am assigning the function to only success variable. But if i go to use the response variable, it actually has a function in it but why? I didnt even assign a value or function to that variable.

Pcall returns the success (true or false) and information if success isn’t true.
So, by declaring local success, response = pcall(function(), you assign to theses values what the function will return.

1 Like

https://developer.roblox.com/en-us/api-reference/lua-docs/Lua-Globals
Documentation regarding pcall can be found here.

2 Likes


Here is pcall and xpcall.

1 Like