i’m curious how heavy pcall is, because i have a loop for simulating all of the projectiles in the game, and if 1 error happens then it breaks permanently. the loop runs for every projectile once every frame and i was curious if i could use pcall up to at most 50 times each frame in order to prevent the projectiles from breaking
Just checked by creating 250 parts using both normal function calls and using pcall:
It’s only slightly slower and I don’t think you’re gonna be creating 250 parts at once anytime soon.
However, I don’t think you should be wrapping them in a pcall at all and you should just handle and prevent the error instead
Code tested with
local function doSomething()
local part = Instance.new("Part")
part.Parent = workspace
end
print("NORMAL")
local a = os.clock()
for i = 1, 250 do
doSomething()
end
print(os.clock() - a)
print("PCALL")
local b = os.clock()
for i = 1, 250 do
pcall(doSomething)
end
print(os.clock() - b)
1 Like
Just because pcall()
catches errors it doesn’t mean those errors are handled, the negative consequences of those errors are still going to take place.