Unable to use CollectionService with GUIs

Hey! So I’ve been trying to use CollectionService with my UI to handle Button Animations. My only Problem is when I play my game, none of the buttons prints out anything or animate. I’ve been looking into a fix but haven’t found one yet. Any help is appreciated.

local ButtonsList = CollectionService:GetTagged("ButtonAnimation")

for _, child in ButtonsList do
    if child:IsA("Frame") then
        local Button = child:FindFirstChild("Button")
        local UIScale = child:FindFirstChild("UIScale")

        Button.MouseButton1Click:Connect(function()
            return print("Clicked")
        end)

        Button.MouseEnter:Connect(function()
            print(child.Name .. " is currently MouseHoverStart.")
            -- Animation Code here
        end)

        Button.MouseLeave:Connect(function()
            print(child.Name .. " is currently MouseHoverLeave.")
            -- Animation Code here
        end)

        Button.MouseButton1Down:Connect(function()
            print(child.Name .. " is currently MouseClickDown.")
           -- Animation Code here
        end)

        Button.MouseButton1Up:Connect(function()
            print(child.Name .. " is currently MouseClickUp.")
            -- Animation Code here
        end)
    end
end
1 Like

Some of the tagged objects could have possibly not loaded in. Use CollectionService:GetInstanceAddedSignal()

Thanks a lot! It finally works.

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