How to Controller and How to MouseAndKeyboard

i have a menu screen and ive been trying to make controller and keyboard work seamlessly but i cant.

question 1. How could I make my script identify which is being used. ex. if controller is connected or controller is used how can i make my script identify that without the controller being pressed?
question 2. how can i make it so it switches seamlessly? ex. keyboard is connected in a console like ps4 or ps5 or the xbox.

note: keyboard and gamepad enabled properties are bools that identify if the experience supports for example gamepads or not. so even if gamepad isnt connected itll say its supported because gamepads are supported or turned on in the experience. so dont say keyboard and gamepad enabled.

I only really need examples. how can i switch seamlessly.

more elaboration on my problem:
So i have a selection frame so it can highlight whats being selected. it works for mouse but not for controller so i scripted it then mouse and controller kinda got mixed.

I can’t exactly help you fix the problem but this should help you: UserInputService | Documentation - Roblox Creator Hub