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)
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.
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.