"growNow isn't a valid member of part workspace.set1-crop.set1"

Before I start, I’d like to say that my English isn’t the best, it isn’t my native language!

What I’m trying to accomplish here is for my script that is in ServerScriptService, is every second the objects in set1-crop folder, specifically the ones named “set1” are checked if their growNow variable is true and if it is the print statement will run (that will eventually be changed to actually function like a real crop) but when I run this it says that the growNow is not a member of set1 in the folder even though when I check the set1 object it shows that it does in fact have the boolean member value thingy. Also for the record, this set1 object is being copied from the ReplicatedStorage director and put into the workspace/folder

here is the hierarchy

Here is my code:


--//Include Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GameWorkspace = game:GetService("Workspace")

--//Directories || F=Folder
local set1CropF = GameWorkspace:FindFirstChild("set1-crop")

while true do
	for _, object in ipairs(set1CropF:GetChildren()) do
		if object:IsA("BasePart") and object.Name == "set1" and object:WaitForChild("growNow") == true then
			print("One of the crops need to grow!")
		end
	end
	wait(1)
end

I’d also like to say that in the IF statement, I tried using FindFirstChild() and just doing object.growNow.Value

I’ve been stuck on this for ~20 minutes and I haven’t found any articles on the developer forum that match my problem.

2 Likes

I can’t exactly figure out what’s wrong, so it would be nice if you could post the entire error message. Also, consider making a few changes to make your code more readable:

Instead of defining workspace, simply use the workspace global, like this:

local set1CropF = workspace:FindFirstChild("set1-crop")

Replace

with

object:FindFirstChild("growNow")

As Wisp pointed out,
“object:WaitForChild(“growNow”) == true”
does not actually work, since Instances aren’t true

Instances are “truthy”, however, which is why you can use

object:FindFirstChild("growNow")

Please also check out the other responses.

1 Like

The == operator checks for strict equivalence. So while yes, Instances are ‘truthy’, they aren’t true. Thus Object:FindFirstChild(...) and Object:FindFirstChild(...) == true are not functionally interchangeable. The latter will always evaluate to false.

I believe they meant to write object:WaitForChild("growNow").Value == true, considering that “growNow” is intended to be a BoolValue. But I can only guess.

1 Like
--//Include Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GameWorkspace = game:GetService("Workspace")

--//Directories || F=Folder
local set1CropF = GameWorkspace:FindFirstChild("set1-crop")

while true do
	for _, object in ipairs(set1CropF:GetChildren()) do
		if object:IsA("BasePart") and object.Name == "set1" and object:WaitForChild("growNow").Value == true then -- Here you forgot to put ".Value" so you are technically looking for a property of some sort. I putted the value and it should work now.
			print("One of the crops need to grow!")
		end
	end
	wait(1)
end

You misunderstood “growNow” for a boolean or just forgot to add .Value. Either, way make sure to thoroughly examine your code before making a report here. I would also suggest to use .Change events as they are more performant and better than using while loops.

You’re right. My apologies.‌‌‌‌‌