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

Why isn't this detecting if v already exists in this table?

Asked by
starmaq 1290 Moderation Voter
5 years ago

So I thought ths 2 lines (not buttons[v]) and buttons[v] = v will stop v from getting inserted to buttons twice, but no it still does.

local buttons = { }
local num = 0


for _, v in pairs (script.Parent:GetDescendants())do
    if v:IsA("TextButton") and (not buttons[v])and v.Name == "l" or v.Name == "o" thn
        v.MouseButton1Click:Connect(function()

            buttons[v] = v
            print(buttons[v])

            v.TextColor3 = Color3.fromRGB(0,255,0)


            num = num + 1
            print(num)
            if  num == 8 then
                print("bloxycola")
            end     
        end)

    end
end

How to prevent this from happening?

1 answer

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

Operator Precedence

You need to place some parentheses around your or pair otherwise it will read the whole thing left to right, fail, and go "Oh, v.Name is "o". Good enough for me."

if v:IsA("TextButton") and (not buttons[v]) and (v.Name == "l" or v.Name == "o") then
0
Hay, thank you! gonna check if it works starmaq 1290 — 5y
Ad

Answer this question