I am trying to use pcall to prevent my code from breaking when a player leaves mid match.
pcall(runGame())
However, after runGame() completes without any errors, I get the error message missing arguemnt 1 at the line I pcall. My research showed that pcall takes a function as argument 1 so I don’t get it.
While the code provided above by @Schedency will work, it creates a new seperate function to run the pcall, you shouldn’t use pcall this way unless you need a seperate function, a better way to do it is as follows, as pcall calls the variable passed to it as a function, just provide it with the function name
local function runGame()
--Function code
end
local success,returnval = pcall(runGame)
if success then
print("Code Run Successfully!")
else
warn(string.format("Error when executing code!\nError: %s",returnval))
--Code to handle errors here
end