Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why does this if statement still work when the parameters are false?

Asked by 3 years ago
Edited 3 years ago
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
0
Used a local script instead of a server script and it works fine now, but why? holamii2 45 — 3y

Answer this question