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:
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.
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
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.
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