Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to check if a part contains a forcefield?

This is what i have:

if part.ForceField == false then

The code dosen't seem to work sometimes, hopefully someone could help.

1 answer

✓ Accepted answer

It doesn't work because you're comparing an object to a boolean, which will always be false. An object is never going to be false, though they are truthy (not false or nil).

Using the :FindFirstChild() function you can do this. It will return nil if the child wasn't found.

if part:FindFirstChild("ForceField") then
    -- Do something if the force field IS found
end

if not part:FindFirstChild("ForceField") then
    -- Do something if the force field is NOT found
end

######Hopefully this answered your question, and if it did, then don't forget to hit that accept button. If you have any more questions, then feel free to leave them down in the comments.

2 comments

0

Thank you, it works!

0

You could just write else, to cut all the lining

This discussion is preserved as it was. New answers, comments, and votes are closed.