so i was trying to check if the weld constraint is in the parent or not apparently comparing it to nil does not work.
if HitBox:FindFirstChild("WeldConstraint") == nil then print("Working") end
Hello there! As by your question it is great for me to assume two things. It appears as if you are trying to detect if an instance is inside an object, and detect if an instance is not inside an object. For this, first let me describe the problem with your previous code.
Your Script:
if HitBox:FindFirstChild("WeldConstraint") == nil then print("Working") end
The problem with the code is that you are trying to detect equivilance. Basically your code is like saying if the FindFirstChild() function with a WeldConstraint parameter is nil then it will execute the code, which is your print command. This is your problem. FindFirstChild() detects if an object or instance of your choice is currently inside, and it will either return true or false (especially because your if statement). It appears as if you are trying to say if there is not a weld constraint (aka FALSE not nil), then execute the following code. Since you are a begginner there is a simple solution for you, which is the keyword not.
Here is a statement, from the lua reference manual:
The logical operators are and, or, and not. Like control structures, all logical operators consider false and nil as false and anything else as true. The operator and returns its first argument if it is false; otherwise, it returns its second argument. The operator or returns its first argument if it is not false; otherwise, it returns its second argument:
That being said, to detect if there is not a WeldConstraint in HitBox, your code should be:
if not HitBox:FindFirstChild("WeldConstraint") then print("Not Working") end
This is simple :)
Now as for your second proposal, to detect if something is Inside of it, you do not need nil, or not. The reason is because that is find first child's primarily function
if HitBox:FindFirstChild("WeldConstraint") then print("Working") end
This is your solution explained in detail. Hope it helped!
FindFirstChild is meant to not error if the instance is nil, so you can remove that “== nil”. Other than that it should work if WeldConstraint is a child of HitBox.
if HitBox:FindFirstChild(“WeldConstraint”) then print(“Working”) end