Hey there,
I'm currently having issues using pcall properly. My loadstring is executing, but without the argument provided, and not functioning properly. Here's what I'm up to:
function confirmCommand(gameCommand) local success, message = pcall(execCommand(gameCommand)) -- line 32 if success then else print("An error occured: " .. message) end end function execCommand(executedCommand) loadstring(executedCommand) end
This is the "secret" script, which is another error I get. It says error loading module yet it still works each time.
require(game.Workspace.Module)
Yes, it's one line.
Here are the errors I receive each time:
14:30:21.559 - Requested module experienced an error while loading 14:30:21.559 - Stack Begin 14:30:21.559 - Script 'Workspace.secret', Line 1 14:30:21.560 - Stack End 14:30:21.560 - Workspace.Module:32: bad argument #1 to 'pcall' (function expected, got no value) 14:30:21.560 - Stack Begin 14:30:21.561 - Script 'Workspace.Module', Line 32 - global confirmCommand 14:30:21.561 - Script 'Workspace.Module', Line 18 - global checkCommand 14:30:21.561 - Script 'Workspace.Module', Line 76 14:30:21.562 - Stack End
Does anyone know what I'm doing wrong?
With pcall the arguments that will be passed to the function needs to be separate.
E.g :-
function confirmCommand(gameCommand) local success, message = pcall(execCommand, gameCommand) -- function then arguments to be passed if success then else print("An error occured: " .. message) end end function execCommand(executedCommand) loadstring(executedCommand) end
Hope this helps.