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

Why does this for i,v in pair loop ignore if statements?

Asked by 4 years ago
Edited 4 years ago
Remove = function(self,Tool)
        for i, v in ipairs(Spots) do
            print(v, Tool, i, Current)
            if v == Tool and tonumber(Current) == tonumber(i) then
                Spots[i] = true
                script.Parent:FindFirstChild(i).IMG.Image = ""
                break
            end
        end
        print("--------------------------------")
    end

Output

 ClassicSword ClassicSword 1 2
  ClassicSword ClassicSword 2 2 -- MATCH
  true ClassicSword 3 2
  true ClassicSword 4 2
  true ClassicSword 5 2
  --------------------------------

In this script, it gets the tools name, but to make the inventory more precise, it also checks the current tool you're holding. As you can see in the output, there was a match, both if statements were fulfilled. But it ignored that and went on. Why does it do this?

Also, spots is just a directory of free spots inside the inventory.


Spots = { [1] = true; [2] = true; [3] = true; [4] = true; [5] = true; }
0
are Tool and Current both a string .... or looking at an objects name? ForeverBrown 356 — 4y
0
I guess its v and tool not tool and current ForeverBrown 356 — 4y
0
Yes, both are objects. They are saved as the Tool object and not a property. goodadmins 111 — 4y

Answer this question