How can I silence this :findfirstchild error?

if PLR:FindFirstChild("CanFightBoss").Value == true then --errors when value doesn't exist
	
else
	
end

Sure I can replace it with

if PLR:FindFirstChild("CanFightBoss") then 
	if PLR["CanFightBoss"].Value == true then

        end
else
	
end

But can I shorten it somehow? Or wrap it in something so that the error is dealt with rather than spamming if statements to check if everything leading up to it is okay?

1 Like

Have you tried :WaitForChild instead of :FindFirstChild?

Maybe try using a pcall to stop the error:

pcall(function()
     -- code here
end)

If you want it to wait for it to exist, use :WaitForChild as @JackIsOP2006 , but if at some point, the value is not in the player and you don’t want to wait for it, you coudl do this

local boss = PLR:FindFirstChild("CanFightBoss")

if boss and boss.Value then 
	
elseif not boss
	
end

Check if the value exists and if it does and its value is true, continue, otherwise check if boss doesn’t eixst

You mean something like this?
Sorry on mobile rn

local object = PLR:FindFirstChild(“CanFightBoss”)

if object then
    if object.Value == true then
        —- etc
    end
end

I think this works too idk?

local object = PLR:FindFirstChild(“CanFightBoss”)

if object and object.Value == true then
    —- etc
end