GetDescendants not working

Hello, I have a script that has to find Bool Values of the many door models and I want this code to find all these Values and change them to true/false, but it’s not working.

local value2 = script.Value

script.Parent.Triggered:Connect(function(player)

	local Tool4 = player.Backpack:FindFirstChild("LVL5")
	local Tool5 = player.Backpack:FindFirstChild("OMNI")
	for index, v in pairs(game.Workspace.Interactables.Doors:GetDescendants()) do

		local value = v:FindFirstChild("Value") == true
		 
	if Tool4 or Tool5 then
		if value and value2.Value then
				wait()
				value = false
			script.Parent.ActionText = "Unlock"
				script.Parent.Parent.Sound4:Play()
				value2.Value = false
			elseif not value and not value2.Value then
				wait()
				value.Value = true
			script.Parent.Parent.Sound4:Play()
				script.Parent.ActionText = "Lock"
					value2.Value = true
			elseif not value and value2.Value or not Tool4 or Tool5 then
				script.Parent.Parent.Sound3:Play()
			end
		end
	end
end)

https://cdn.discordapp.com/attachments/834832439087726622/928272653276577912/Screenshot_380.png

(Check Picture link above!)

Would you not do :GetChildren() ?

That doesn’t work too. Maybe it is something with checking the value if it’s true or not.

Can you show us the layout of one of the doors?

There’s a picture link above, just click on it and you can see the model on the right.

Get descendants return every instance, whether children or parent. Try using:

for index, v in pairs(game.Workspace.Interactables.Doors:GetDescendants()) do
     if v.Name == "Value" then
           v.Value = false

Also ur code won’t work anyway, bcuz you changed the instance to true not .Value

@EIiteCore did this work?

break of your code breaks your iteration after 1 cycle.
You should move break to a different stack level to fix it.

local value2 = script.Value

script.Parent.Triggered:Connect(function(player)
	local Tool4 = player.Backpack:FindFirstChild("LVL5")
	local Tool5 = player.Backpack:FindFirstChild("OMNI")
	for index, v in pairs(game.Workspace.Interactables.Doors:GetDescendants()) do
		local value = v:FindFirstChild("Value") == true
		if Tool4 or Tool5 then
			if value and value2.Value then
				wait()
				value = false
				script.Parent.ActionText = "Unlock"
				script.Parent.Parent.Sound4:Play()
				value2.Value = false
			elseif not value and not value2.Value then
				wait()
				value.Value = true
				script.Parent.Parent.Sound4:Play()
				script.Parent.ActionText = "Lock"
				value2.Value = true
			elseif not value and value2.Value or not Tool4 or Tool5 then
				script.Parent.Parent.Sound3:Play()
			end
		end
		break
	end
end)

As you can see above, after formatting, you may notice the break is in the same stack with the for ~ do loop

If I remove it, it is opening and closing at the same time, sounds are playing like 10 times very fast, it’s starting to loop and I do not know where I can put it, I actually just want a script that finds all bool values of all the door models and checks if they are true or false and I don’t want it to be looped, it should just do it once.

@Mystxry12 No, it does not, but thanks.

GetDescentants does not return every instance…? I returns all the descendants of the Instance that it was called on, that means: children, children of children, etc.

Yes, removing it will result in behavior that you are not intending to happen.
It would be helpful if you explain the goal of your script if it doesn’t bother you.

local value = v:FindFirstChild("Value") == true
You’re checking if FindFirstChild returns a true. FindFirstChild returns the Value, if it found any, otherwise, it returns nil.

Its probably erroring here. You should try an if statement around it and carry on with the script if needed. Are you getting any errors?

That doesn’t work either.

@Actulurus How can I check then if the “Value” boolean is true or not?

Check if “Value” boolean is true? I don’t know what you mean by this, you can do if Value then

Just below here, try

print(v.Name)

And if items are printing then it rules out an error with that

Also just a tip, with for loops if you are not using index simply set it to an underscore, it saves memory

At the right you can see what I’ve marked and I want the script to check all the values of the doors if the value is ticked (true).

You have to do Value.Value then, as the Value instance contains a Value property

That would be a problem I would point out, but the operator == actually checks the state of the given object. Although yes, they need to add .Value.

try to use FindFirstChildOfClass.

If v:FindFirstChildOfClass("BoolValue") then

end

Nevermind, I did it in an other way. Thanks to everyone who helped.