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)
UserInputService is supposed to be used in local scripts, not in server scripts.
Try writing your script in a LocalScript inside of StarterPlayer->StarterPlayerScripts.
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.
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.
.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)