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

Why does a certain pcall work for my script and return?

So the title is confusing here's what I mean

This one prints True,True

local ProductFunctions = {

[1] = function(player)
   
 
   print("player is not a player")
   return true

end

};




local handler = ProductFunctions[1];
local player  = game.Players:WaitForChild('Roblox');

local s, e = pcall(handler,player)
	

print(s, e) -- Prints True, true which i want





But if i change up the pcall

local ProductFunctions = {

[1] = function(player)
   
 
   print("player is not a player")
   return true

end

};




local handler = ProductFunctions[1];
local player  = game.Players:WaitForChild('Roblox');

local s, e = pcall(function()
	handler(player)  
end)

print(s, e) -- WONt print true,true  prints true,nil

1 comment

0

I hope my solution helps! :))

1 answer

You have to return it by the pcall, I fixed your code like this.


local ProductFunctions = {
[1] = function(player)


   print("player is not a player");
   return true

end
};
local handler = ProductFunctions[1];
local player  = game.Players:WaitForChild('Roblox');
local s, e = pcall(function()
    return handler(player)  
end)
print(s, e); -- print true,true

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