I just recently came across someone using pcall and tried to implement it into my script so that no errors are produced, am I using this correctly?
script.Parent.Touched:connect(function(hit)
pcall(function()
humanoid = hit.Parent.Humanoid--this produced an error if it wasn't touching a player/humanoid, but its fine now that i put it in this pcall
end)
if humanoid then
humanoid.Health = humanoid.Health - damage
end
end)
This script works, but is there a way to improve it?
EDIT: i just realized I could use
local humanoid = hit.Parent:FindFirstChild("Humanoid")
instead, but could someone explain me to where i should use pcall

1 comment
Also, you may read this for more info: https://devforum.roblox.com/t/pcalls-when-and-how-to-use-them/393687