Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

1 comment

0

Hay, thank you! gonna check if it works

This discussion is preserved as it was. New answers, comments, and votes are closed.