local Inventory = script.Parent.Parent.Parent.Parent.Parent.Inventory
local children = script.Parent.Ingredients:GetChildren()
local count = #children

script.Parent.MouseButton1Click:Connect(function()
	local canBrew = 0
	for _, ingredient in ipairs(children) do -- IntValue of # of ingredients needed
		local invIngredient = Inventory[ingredient.Name] -- IntValue of # of ingredient in player's inventory
		if invIngredient.Value >= ingredient.Value then
			print(invIngredient.Name)	
			canBrew +=1
			print(canBrew)	
		else print("Not enough")	
		end
	end

	if canBrew == count then -- if all ingredient requirements are met
		print("Brewed!")
	end
end)

I'm having a problem where it still adds +1 to canBrew even though the number of ingredients in the player's inventory is less than the amount needed. The output is the same when the amount of ingredients I have is more, less, or equal to the ingredients I need.

the output is shown here

Swiftthistle  -  Server - BrewScript:11
1  -  Server - BrewScript:13
Silverleaf  -  Server - BrewScript:11
2  -  Server - BrewScript:13
Earthroot  -  Server - BrewScript:11
3  -  Server - BrewScript:13
Mageroyal  -  Server - BrewScript:11
4  -  Server - BrewScript:13
Peacebloom  -  Server - BrewScript:11
5  -  Server - BrewScript:13
Brewed!  -  Server - BrewScript:18

1 comment

0

Used a local script instead of a server script and it works fine now, but why?