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

Returning Something in pcall using functions?

local function ReturnSomething()
	return 'Hi'
end


local S,E = pcall(function()
	ReturnSomething()
	
	
end)

print(S,E) 

this prints (true , nil)

for some reason

I cant get a function to return something to a pcall

I want E to return Hi not nil how do i do this

1 answer

You need to return it in the actual pcall() callback, instead of in your function.

ie:

local S, E  = pcall(function()
	return "Hi"
end
print(S, E)

true, Hi

  • or, if I were to edit your approach -
local function returnSomething()
	return "Hi"
end

local S, E = pcall(function()
	return returnSomething()
end)

print(S, E) 

true, Hi

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