UserInputService not working?

I want the user to press “M” to access the menu, which is inside playerGUI. The script is inside ServerScriptService.

The issue is that nothing is happening. I press M and nothing happens.

Code

local UserInputService = game:GetService("UserInputService")
local debounce = false

UserInputService.InputBegan:Connect(function(player, input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if (input.KeyCode == Enum.KeyCode.M) then
			if debounce == false then
				debounce = true
				player.PlayerGui.MorphTeamSelection.TeamSelect.Visible = true
				print(player.DisplayName.." has opened the menu!")
				wait(3)
				debounce = false
			end
		end
	end
end)
1 Like

try running the code in the command line just to see if its the UIS or the actual code

game.Players.LMVM2041.PlayerGui.MorphTeamSelection.TeamSelect.Visible = true

if this doesnt work then its UIS

otherwise its ur GUI stuff

UserInputService is supposed to be used in local scripts, not in server scripts.
Try writing your script in a LocalScript inside of StarterPlayer->StarterPlayerScripts.

I also recommend using ContextActionService for GUI related keybinds.

I am getting this error:

Players.LMVM2041.PlayerScripts.LocalScript:5: attempt to index boolean with 'UserInputType'

Okay, try this in your local script:

local UserInputService = game:GetService("UserInputService")
local debounce = false
local player = game.Players.LocalPlayer

UserInputService.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if (input.KeyCode == Enum.KeyCode.M) then
			if debounce == false then
				debounce = true
				player.PlayerGui.MorphTeamSelection.TeamSelect.Visible = true
				print(player.DisplayName.." has opened the menu!")
				wait(3)
				debounce = false
			end
		end
	end
end)

The InputBegan event shouldn’t have “player” as an argument, that’s why you declare the variable player beforehand.

2 Likes

Kept having this issue, stopped when I moved all the UserInputService parts of my game to 1 localscript

Your code should bee inside the StarterPlayer folder inside a Local Script UserInputService isnt used on the server side

A LocalScript …
Placed in: game.StarterPlayer.StarterPlayerScripts or in game.StarterGui

local uis = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local mts = player.PlayerGui.MorphTeamSelection.TeamSelect
uis.InputBegan:Connect(function(input, processed)
	if input.KeyCode == Enum.KeyCode.M then mts.Visible = true
		print(player.DisplayName.." has opened the menu!")
	end
end)

First of all, your script has to be in a local script (in a place where the script will run, such as StarterPlayersScripts). Second of all, there isn’t a player argument in InputBegan, so take that out.

This is wrong,

1. this script should be placed in a LocalScript not a ServerScript

2. UserInputService.InputBegan:Connect(function(player, input)

.There is no such thing as a “player” parameter in UserInputService.

.Input is an Enum.KeyCode Data Value, you are getting this error because you placed input in second parameter which is supposed to be for the UserInputService’s GameProccssedEvent – if the player is typing.

so to fix this script, paste this in that entire section of code:

local UserInputService = game:GetService(“UserInputService”)
local debounce = false

UserInputService.InputBegan:Connect(function(input, isTyping)
        if isTyping then return end

	if input.UserInputType == Enum.UserInputType.Keyboard then
		if (input.KeyCode == Enum.KeyCode.M) then
			if debounce == false then
				debounce = true
				player.PlayerGui.MorphTeamSelection.TeamSelect.Visible = true
				print(player.DisplayName.." has opened the menu!")
				wait(3)
				debounce = false
			end
		end
	end
end)