UserInputService Not Working

  1. What do you want to achieve? I’m trying to check if a player has a certain username, then make something happen once they press the P key if they do have a certain username.

  2. What is the issue? The script is detecting if a player has the correct username, but is not detecting the pressing of the P key, and I don’t know what the problem is.

  3. What solutions have you tried so far? I’ve looked on the developer forums and tried for a while to do it myself, but I haven’t been able to figure out the problem, and I’m not getting any errors in the output window.

Here is the code if you need it.

local TS = game:GetService("TeleportService")
local names = {"VisibleContrast"}
local UIS = game:GetService("UserInputService")

game.Players.PlayerAdded:Connect(function(player)
	for i, v in pairs(names) do
		if v == player.Name then
			print(player.Name)
			UIS.InputBegan:Connect(function(input)
				if input.KeyCode == Enum.KeyCode.P then
					print("Opening developer panel.")
				end
			end)
		end
	end
end)

I would appreciate any help I can get.

You can’t use user input service in a server script

Oh, ok. I didn’t know that. I’ll try to change something to fix it.

I’d suggest using a remote event and having uis in the local script

1 Like

It worked, thank you for the help.

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