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

What does the parameter of Pcall Do I don't understand where it saids func,tuple args?

So I stumbled across the parameters of PCALL and wondered how I can use it

it saids first parameter is function and the other one is a tuple

but I don't have a idea on how to use it

For Example

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("DataStoreName")



-- getting data
local success, result = pcall(DataStoreService.GetAsync, DataStoreService, "Gay")

if success then
   print('G')

 -- do something to result
else
    -- result is the error message
end


But if I tried

DataStoreService.GetAsync

Outside Pcall it would error

1 answer

✓ Accepted answer

The other arguments to pcall will be the ones used as arguments in the function assigned to said pcall's first parameter. Here's an example to better explain what I mean by that:

-- The function to be called
function OnPcall(string1, string2, string3)
	return string1 .. " " .. string2 .. " " .. string3
end

-- "Hello", "my" and "friends!" will be passed to our function OnPcall
local success, message = pcall(OnPcall, "Hello", "my", "friends!")
if success then
	print("Message: " .. message)
else
	warn("Error: " .. message)
end

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