Doesn't check if exists

How can i not get an error if that doesnt exist?

if Tool.Shell.Shell then -- error code here
	Tool.Shell.Shell:Emit(Tool.Shell.Shell:GetAttribute("EmitCount"))
end

image

I also tried

local shell = Tool:FindFirstChild("Shell"):FindFirstChild("Shell")
if shell ~= nil then -- error code here
	shell:Emit(Tool.Shell.Shell:GetAttribute("EmitCount"))
end

but that gives the same error

Im not sure but…

:face_with_raised_eyebrow:

1 Like

If the first Shell isn’t found, then FindFirstChild returns nil. When you do it again, you’re using an instance method on a nil value, and it still errors. Try this:

if Tool:FindFirstChild("Shell") then
  if Tool.Shell:FindFirstChild("Shell") then
    -- other code goes here
  end
end
3 Likes