Checking for multiple BoolValues

Hey guys!

I’m trying to make a script that checks if three separate BoolValues are checked. Here’s my script:

holders = script.Parent.Parent
cube = holders.CubeHolder
cylinder = holders.CylinderHolder
pyramid = holders.PyramidHolder
-- Each of these models have a BoolValue in them.

if cube.BoolValue.Value == true and cylinder.BoolValue.Value == true and pyramid.BoolValue.Value == true then
    print("Good.)
end

Sadly this does not work. Anyone know how to fix this?

1 Like

Are the values already set to true, or are you changing them somewhere?

Also, the lack of a closing quotation mark here will throw an error.

Yeah, I am changing them over time on player activated events.
Also that quotation mark doesn’t matter; I just typed out my script and had a punctuation error.

If your waiting for a event and then these to fire, that wont work. This if only checking if the statements are true once. Place it in a loop for it to check multiple times.

Your current code only checks their initial values. I would use the BoolValue.Changed event to detect when they update.

Code

local Container = script.Parent

local function CheckValues()
	for i, v in pairs(Container:GetChildren()) do
		if v:IsA("BasePart") and not v.BoolValue.Value then
			print("At least one value is false")
			return false
		end
	end
	
	print("All values are true")
	return true
end

for i, v in pairs(Container:GetChildren()) do
	if not v:IsA("BasePart") then continue end
	
	v.BoolValue.Changed:Connect(function()
		CheckValues()
	end)
end

Hierarchy

image

1 Like