Small question about for loops

Here I have this table, and a script that will check the players stats to see if they meet the conditions I have put in the table using a for loop.

Whats supposed to happen is that if the player meets ALL conditions, it will print out “Conditions Cleared” but my issue is that if the player only meets ONE condition, it will still print out

My question is how do I make a for loop check every table so that the player must have all conditions checked for the print statement to run

module.Recipies = {
	["Exalted"] = {
		Name = "Exalted",
		Energy = 50,
		Runes = {
			[1] = {Rune = "Temporal", Ammt = 500},
			[2] = {Rune = "Larimar", Ammt = 50},
			[3] = {Rune = "Sugilite", Ammt = 10},
		}
	},
}

function module.Craft(plr, stat)
	local energy = plr.Data.Crafting.Energy
	local stat = module.Recipies[stat]
	
	if energy.Value >= stat.Energy then
		for i, v in ipairs(stat.Runes) do
			if v.Ammt <= plr.Data.Runes[v.Rune].Value then
				print("Conditions Cleared")
			end
		end
	end
end
module.Recipies = {
	["Exalted"] = {
		Name = "Exalted",
		Energy = 50,
		Runes = {
			[1] = {Rune = "Temporal", Ammt = 500},
			[2] = {Rune = "Larimar", Ammt = 50},
			[3] = {Rune = "Sugilite", Ammt = 10},
		}
	},
}

function module.Craft(plr, stat)
	local energy = plr.Data.Crafting.Energy
	local stat = module.Recipies[stat]
	local cleared = 0

	if energy.Value >= stat.Energy then
		for i, v in ipairs(stat.Runes) do
			if v.Ammt <= plr.Data.Runes[v.Rune].Value then
				cleared += 1
			end
		end
		
		if (cleared >= #stat.Runes) then 
			print("Conditions Cleared")
		end
	end
end
1 Like

Hi!

Did you mean to use the less than operator here? Also, what are the values you are referencing?

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