Issues with tracking keyboard input

Hello everyone

So, I have a problem with tracking the change of a player input, like when the player goes on Gamepad mode, or if a player goes back onto Keyboard

I have this script right here, and it is supposed to detect when the player changes to Keyboard or Gamepad, but it only detects when the Gamepad input is changed, which is weird (this script is a LocalScript inside of StarterPlayerScripts)

local UserInputService = game:GetService('UserInputService')

UserInputService.InputChanged:Connect(function(input)
	if (input.UserInputType == Enum.UserInputType.Keyboard) then
		UserInputService.MouseIconEnabled = true
        print('Keyboard')
	elseif (input.UserInputType == Enum.UserInputType.Gamepad1) or (input.UserInputType == Enum.UserInputType.Gamepad2) then
		UserInputService.MouseIconEnabled = false
        print('Gamepad')
		return input
	end
end)

Oh yeah, if the input is changed to Gamepad, the mouse will turn off. Now if the input is changed to Keyboard, then the mouse will turn on. Also, whenever i switch back to keyboard (Which is when the mouse is hovering over the output,) the mouse wont be turned on, and it will not print “Keyboard”, which is shown here;

Any help on how to fix this issue? please and thank you

local UserInputService = game:GetService('UserInputService')

UserInputService.LastInputTypeChanged:Connect(function(input)
	if input== Enum.UserInputType.Keyboard then
		UserInputService.MouseIconEnabled = true
		print('Keyboard')
	elseif input.Name:find("Gamepad") then
		UserInputService.MouseIconEnabled = false
		print('Gamepad')
	end
end)
2 Likes

appreciate it

max characters this that and the thrirjeoiwh

2 Likes