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

How do I fix this conditional statement?

Asked by 7 years ago
script.Parent.Touched:connect(function(part)
    if part.Parent.Dirt == nil then
        print("It's working")
    end
end)

Okay, according to the code, or at least what I think should happen, is that if the object "Dirt" does not exist in the parent of part, then it should print "It's working". But umm, yeah it doesn't do that, it just errors "Dirt is not a valid member of Model" and doesn't do anything inside the if statement. If you guys could maybe help me find a way to word it better or point out my errors then thank you.

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

Hey Your_Momdotcom,

You have sort of the right idea but, it's done in a different way. You have to use :FindFirstChild() and not method for this. Here, check this code out below as an example.

local part = workspace:FindFirstChild("Part")

if not part then
    print("It's working...")
end

Well, I hope that helped and if you want to view the wiki pages for 'not' or ':FindFirstChild()' then just click on the words in this answer and it should take you there.

~~ KingLoneCat

0
Thanks, makes sense. Your_Momdotcom 91 — 7y
1
Thanks, can you accept the answer so people know that this has been answered and they don't have to bother with it. KingLoneCat 2642 — 7y
0
findFirstChild is deprecated. Use FindFirstChild. BlueTaslem 18071 — 7y
0
Yea, mb. I switched over and over. KingLoneCat 2642 — 7y
Ad

Answer this question