✓ Accepted answer
pcall allows you to run the lines of code inside it in "Protected mode" so that if there is an error the script doesn't break. pcall holds 2 parameters. The first parameter returns a boolean, You can use this, later on, to check if there are any errors in the code. The second argument returns a variant. If there were any errors in the code you can use print() to show what kind of error it was. Basically, it would show the same error as it would without pcall. A pcall function would look like this:
local success, message = pcall(function()
end)
if success then
else
print(message)
end
You can also use warn() instead of print if you want to.
Now, the thing is that pcall doesn't re-run the function for you. So what you can do is to call upon a function with pcall.
local function hit(p)
print(p)
end
script.Parent.MouseClick:Connect(function(player)
local Success, Message = pcall(hit, player)
end)
Normally to pass of a parameter inside the brackets of a function like
hit(player) but if you look at the explanation for the pcall you see that it takes a parameter after a function. (I'm sorry if I explained that poorly. English isn't my native language)
1 comment
@noammao wow really helped