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

Why does FindFirstChild does not work when I include it?

Im writing some code and when i dont include FindFirstChild it worked and i make sure that when i have FindFirstChild there is no "Jar" object in the part. Why is it not working?

Here is the code:

script.Parent.Touched:Connect(function(part)
	local parent = part.Parent
	if parent.Name == "Jar" and script.parent:FindFirstChild("Jar", false) then
		print("Test")
	end
end)

4 comments

0

do you want to find "Jar" when you say :FindFirstChild() ?

0

i want to make sure there is no jar

0

k

0

i put an answer try it

2 answers

instead of

if parent.Name == "Jar" and script.parent:FindFirstChild("Jar", false) then

do

if parent.Name == "Jar" and script.parent:FindFirstChild("Jar") == false then

7 comments

0

doesnt work

0

so u tried the second one?

0

yes

0

do you wanna see if the script's parent has jar? cuz u put if parent.Name == "Jar" and script.parent:FindFirstChild("Jar", false) then

0

yes

0

He_ishee I’m sending you a friends req on Roblox. We can go into studio together and fix this.

0

replace false with nil

coolmcroy was on the right track, but :findfirstchild() returns nil if it finds nothing, not false. your if statement should look like this:

if parent.Name == "Jar" and not script.parent:FindFirstChild("Jar") then

since 'not' looks for the absence of true, it will pass if findfirstchild returns nil or false, which is what you want.

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