Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to check if a part contains a forcefield?

Asked by 6 years ago

This is what i have:

if part.ForceField == false then

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

1 answer

Log in to vote
0
Answered by 6 years ago

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.
0
Thank you, it works! mrfrank79 30 — 6y
0
You could just write else, to cut all the lining User#25448 0 — 6y
Ad

Answer this question