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

How do I fix this conditional statement?

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

✓ Accepted answer

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

4 comments

0

Thanks, makes sense.

1

Thanks, can you accept the answer so people know that this has been answered and they don't have to bother with it.

0

findFirstChild is deprecated. Use FindFirstChild.

0

Yea, mb. I switched over and over.

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