Checking If Values In Table Are CURRENTLY "true" [SOLVED]

  1. What do you want to achieve? Keep it simple and clear!
    I want a part to become transparent when I click it only when all the values in a table are true when I click on the part.

  2. What is the issue? Include screenshots / videos if possible!
    The issue is that the part will become transparent when clicked even if the conditions in my table WERE true but no longer true.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried to change the table conditions to other things like part postions but that doesnt change my issue. The script will still turn my part transparent on click as long as the conditions in the table ARE or WERE true, but I want it to only work when the conditions are currently true.

local ClickDetector = script.Parent.ClickDetector

function onMouseClick(player)	
local Conditions = 
		{game.Workspace.Comic1Tool.PlacementCheck.Value,
		game.Workspace.Comic2Tool.PlacementCheck.Value} 

	for i,v in Conditions do
		if v == true then
	script.Parent.Transparency = .5
	end
end
	end
ClickDetector.MouseClick:Connect(onMouseClick)

PlacementCheck is a BoolValue and the Value is only true when the parent, a tool, is on a certain position. And my table is supposed to check for when these BoolValues are enabled for my function to work.

1 Like

What about, do the loop checking each condition, if any is false, then a main lock is false, and the part will become transparent ONLY if lock is true

local ClickDetector = script.Parent.ClickDetector

function onMouseClick(player)	
	local Conditions = {
		game.Workspace.Comic1Tool.PlacementCheck.Value,
		game.Workspace.Comic2Tool.PlacementCheck.Value
	} 
	
	local lock = true
	
	for i, v in Conditions do
		if not v then
			lock = false
		end
	end
	
	if lock then
		script.Parent.Transparency = 0.5
	else
		warn("not all conditions were true")
	end
end
ClickDetector.MouseClick:Connect(onMouseClick)
1 Like

Omg this worked! Ok I see what you mean, I should of also checked for when the value would be false too. Thank you sm that was such an easy way to fix it! Marked it as the solution too c:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.