FindFirstChild not working as designed?

Hello everyone.

I’m just in the middle of scripting a new main menu for a group I’m in. I have it setup to where if they click a button, it’ll play a sound, but if the button exists in another part of the GUI, it’ll play the following tween:

The problem is, the script as it stands specifically names the button like this:

for i, v in pairs(base:GetDescendants()) do
	
	if v:IsA("TextButton") then
		
		v.MouseEnter:Connect(function()
			
			sfx.Hover:Play()
			
		end)
		
		v.MouseButton1Click:Connect(function()
			
			if v.Name == "Teams" then --<HERE
				
				selectedframe = v.Name
				
				local slidein = ts:Create(base.Main[selectedframe], TweenInfo.new(0.5), {Position = UDim2.new(0, 0, 0, 0)})
				local slideout = ts:Create(base.Main[currentframe], TweenInfo.new(0.5), {Position = UDim2.new(-1, 0, 0, 0)})
				
				slidein:Play()
				slideout:Play()
				
				currentframe = v.Name
				
			end
			
			sfx.Click:Play()

		end)
		
	end
	
end

But when I use FindFirstChild, it doesn’t do anything. No error is there, and I have checked that the instance does infact exist where I specified.

		v.MouseButton1Click:Connect(function()
			
			if v.Name == base.Main:FindFirstChild(v.Name) then
				
				selectedframe = v.Name
				
				local slidein = ts:Create(base.Main[selectedframe], TweenInfo.new(0.5), {Position = UDim2.new(0, 0, 0, 0)})
				local slideout = ts:Create(base.Main[currentframe], TweenInfo.new(0.5), {Position = UDim2.new(-1, 0, 0, 0)})
				
				slidein:Play()
				slideout:Play()
				
				currentframe = v.Name
				
			end

It doesn’t display errors, so I have no idea what to do here. Can I get some help please?

1 Like

Try using the lua debugger. You can set a breakpoint in your program, and then step through it line-by-line and inspect what all the variables are at each step. Might help you figure out what’s wrong.

1 Like

I’ll give that a look, I’ll let you know what comes up.

why are you comparing a name to an instance? it’s always going to return false

It isn’t… It’s comparing one string to another.

shouldn’t you be doing base.Main:FindFirstChild(v.Name).Name?

1 Like

No, you put what you’re looking for inside the “()”.

Ignore me, you were right. Thank you so much!