How can i get a value that is inside 2 if statement?

I’m making a system that involves putting “ingredients” into a specific cauldron.
The part of the code where I’m having problems is this:

game.ReplicatedStorage.RemoteEvent1.OnClientEvent:Connect(function(NomeDoCaldeirao,TipoDeIngrediente)
print(NomeDoCaldeirao) → foz example: “A”,“B”…
print(TipoDeIngrediente) → for example: 0,1,2,3…
local PrimeiroIngredienteEmA = false
local PrimeiroIngredienteEmB = false
local BagasEmA = false
local BagasEmB = false
local BeijoDeFadaEmA = false
local BeijoDeFadaEmB = false
local ColorTemp = Color3.fromRGB(0,0,0)
local ColorTempR = Color3.fromRGB().R
local ColorTempG = Color3.fromRGB().G
local ColorTempB = Color3.fromRGB().B

if NomeDoCaldeirao == "A" then --> Checks if the cauldron name is A
	if PrimeiroIngredienteEmA == false then --> checks whether or not the first ingredient has been added
		if TipoDeIngrediente == 0 then --> if "bagas" was selected
			ColorTemp = Color3.fromRGB(85, 0, 127)
			local op = Instance.new("TextLabel",script.Parent["CraftPoçoesFrame"]["PoçoesUsadasScrollingFrame"].ContentAmountFrameA) op.Name = "BagasTextLabel" op.Text = "1"
			local opi = Instance.new("ImageButton", script.Parent["CraftPoçoesFrame"]["PoçoesUsadasScrollingFrame"].ContentIconsFrameA) opi.Name = "BagasImageButton" opi.Image = ""
			BagasEmA = true
			PrimeiroIngredienteEmA = true
			script.Parent["CraftPoçoesFrame"].CorAtualFrameA.NadaTextLabel.Visible = false
			script.Parent["CraftPoçoesFrame"].CorAtualFrameA.BackgroundColor3 = ColorTemp
			print(PrimeiroIngredienteEmA)
		elseif TipoDeIngrediente == 1 then --> if "Beijo de Fada" was selected
			ColorTemp = Color3.fromRGB(65, 65, 65)
			local op = Instance.new("TextLabel",script.Parent["CraftPoçoesFrame"]["PoçoesUsadasScrollingFrame"].ContentAmountFrameA) op.Name = "BeijoDeFadaTextLabel" op.Text = "1"
			local opi = Instance.new("ImageButton", script.Parent["CraftPoçoesFrame"]["PoçoesUsadasScrollingFrame"].ContentIconsFrameA) opi.Name = "BeijoDeFadaImageButton" opi.Image = ""
			BeijoDeFadaEmA = true
			PrimeiroIngredienteEmA = true
			script.Parent["CraftPoçoesFrame"].CorAtualFrameA.NadaTextLabel.Visible = false
			script.Parent["CraftPoçoesFrame"].CorAtualFrameA.BackgroundColor3 = ColorTemp
			print(PrimeiroIngredienteEmA)
		end
	elseif PrimeiroIngredienteEmA == true then
		print("dsddsfdsfdsdfs")
	end
end

end)

What problem do I have? As you can see in the code the “PrimeiroIngredienteEmA” will be true at the end if it was false before.
The problem is that in the “elseif FirstIngredientInA == true then” part it will continue to be false for some reason.
What am I doing wrong? (It seems that the problem is in the “ifs” but I don’t know if this is the real problem)

I had discovered this a few hours later, I already saw where the problem is, it’s just because the booleans were out of the function.

Hi!

I didn’t read the whole code, since it was a bit messy for me to read.

But here’s an idea you could use.

For your cauldron, have the inserted ingredients set as attributes, and then just check if the required attributes is present in the cauldron.

local Cauldron = ....
local RequiredIngredients = {
["SpeedPotion"] = {"Sugar", "Water"},
["JumpPotion"] = {"Carrot","Water"},
}
-- Inside the function
local Potion = "SpeedPotion" -- define yourself which potion to create
local Success = true
for _, Ingredient in pairs(RequiredIngredients[Potion]) do
	if not Cauldron:GetAttribute(Ingredient) then
		Success = false
		break
	end
end
if Success then
--Create potion
end