Pcall Necessity

Just a quick question about pcall…

Should I use pcall even though I know there is no reason for an object not to exist?

For example, I’m freely referring to Humanoid of another player’s character. I know that there is no scenario where the humanoid would not exist, unless the client is an exploiter and purposefully deletes that player’s humanoid.

In a case where a humanoid does not exist, the client would be introduced with a load of nasty bugs. Should I be concerned about this?

My gut is telling me no.

1 Like

You could just do

local humanoid = character:FindFirstChildOfClass("Humanoid")

if humanoid then
    -- do things
end

pcall wouldn’t be necessary here

1 Like

If you aren’t sure whether or not an object has loaded by the time the script has run, :WaitForChild() is always available for use. You will only ever need a pcall if the code is running asynchronously (HTTP, DataStores, etc).

1 Like

It’s usually good practice to be sure if something exists. You dont have to use pcall though, you can always use FindFirstChild or WaitForChild depending on the situation.

1 Like

There is an extensive tutorial about protected call, which pcall stands for.

1 Like