UserInputService not work

Hello I made a game, then I added E press to open code but it does not work I can someone help

local active = false
local use = script.Parent.Using
local userInputService = game:GetService("UserInputService")


	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player and use.Value == false then
		if not active then
		active = true
		local React = script.Parent.Parent.ReactionUI
		local React2 = React:Clone()

			React2.Parent = player.PlayerGui
            React2.Name = "React2"
			userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
				if input.UserInputType == Enum.UserInputType.Keyboard then
					if input.KeyCode == Enum.KeyCode.E then
						print("You pressed E")

	active = false
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player and use.Value == false then
		local RecUI = player.PlayerGui:FindFirstChild("React2")

1 Like

Try printing out ‘input.Keycode’, check if the connection is even running in the first place.

not working what should I do ?

It looks to me this is in a server script, UserInputService doesn’t run in server scripts, only on client.

To fix this, you can clone a script into the player which has the UIS part of it, then fire an event to the server when the input is pressed.

Also, what you’re doing here by placing that connection inside of touched isn’t a good idea, as you’re going to create an over abundance of connections all doing the same thing.

1 Like

Each of these events (touched and input Began) can’t run together, each of them runs somewhere else (server and client), you can try ContextActionService, I think it works on the server.

Where is your script located? It’s supposed to be a LocalScript in StarterPlayer/CharacterScripts

The touched event won’t fire if it’s a local script.

this normal script code but soluted

Wait, I just realised, why would you connect in a event inside of an Event Listener? Isn’t using RemoteEvents a solution

UserInputService only works on client and touched only works on server, they can’t work together.

Yes that is correct, everyone has his own way.