TextButton is NOT detecting MouseButton1Down

Hey! I want the output to print “Bubble Egg clicked!” when the player presses on the ‘Bubble Bunny equip’ TextButton.

When you press on any other button, it prints correctly. The ‘Bubble Bunny equip’ TextButton prints nothing when I press on it & it doesn’t seem to change colour when I hover over it. Here’s a video showing it happen:

I’ve searched for solutions on the internet & wondered for hours what the problem could be but I’m completely lost.

Here’s the ScreenGui in StarterGui:
unlockedBunniesGUI

This is the LocalScript called ‘BunnyGUIScript’:

local scrlFrame = script.Parent:WaitForChild("ScrollingFrame")

for i, button in pairs(scrlFrame:GetChildren()) do
	wait(1)
	if button:IsA("ViewportFrame") and button.Name ~= "Starter Bunny" then
local textBtn = button:WaitForChild("TextButton")
print(button.Name)
		
		textBtn.MouseButton1Down:Connect(function()
			print(button.Name,"clicked!")
end)
end
end

If you have an idea as to what the problem could be, please let me know as any help at all would be greatly appreciated! Thanks for reading.

1 Like

There is maybe a problem with the TextButton, try deleting it and making it again, or duplicate it from a working one.

1 Like

I tried duplicating it from a working one & it was still broken. I’m very confused… Thanks for your reply though!

Most probably, you have another GuiObject infront of it, either change the Z-index or move it away.

1 Like

InsideButton
This is what’s inside of the ViewportFrames. The TextButtons have a ZIndex of 2 whereas everything else has a ZIndex of 1.

1 Like

Probably one of the children, children are always on top of their parents (except if you changed ScreenGui’s properties which mostly isn’t the case).

1 Like

There’s only a UICorner inside of the TextButtons to make the buttons rounded.

Based upon this code it does not look like you assigned a parent for the button. Perhaps you meant to and forgot? =p

1 Like

This code loops through the children of the ScrollingFrame & checks if each one is a ViewportFrame. It then checks if there’s a TextButton in each ViewportFrame. As you can see in the video, the output prints out all of the TextButtons names including the broken TextButton.

Perhaps the code ran before all of them had loaded in? Would something like the below help?

local amoutNeededToProceed = 14

repeat
    local eggsTemp = 0
    for _, v in ipairs(scrlFrame:GetChildren()) do
        if v.Name:match("Egg$") ~= nil then
            eggsTemp = eggsTemp + 1
        end
    end
    wait(2)
until #eggs == amoutNeededToProceed
1 Like

Thanks for your reply. I added this at the beginning of my LocalScript:

local amountNeededToProceed = 13

repeat
	local eggsTemp = 0
	for _, v in ipairs(scrlFrame:GetChildren()) do
		if v.Name:match("Egg$") ~= nil and v:FindFirstChild("TextButton") then
			eggsTemp += 1
			print(eggsTemp)
		end
	end
	wait(2)
until amountNeededToProceed <= eggsTemp

It printed up to 13 but the TextButton still isn’t working.

Ohh. Then try this code:

local scrlFrame = script.Parent:WaitForChild("ScrollingFrame")

for i, button in pairs(scrlFrame:GetChildren()) do
	task.wait(1)
	if button:IsA("ViewportFrame") and button.Name ~= "Starter Bunny" then
		local textBtn = button:WaitForChild("TextButton")
		print(button.Name)
		
		textBtn.MouseButton1Down:Connect(function()
			print(button.Name,"clicked!")
		end)
	end
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.