Part not responding on UserInputService

I want to when I click “Q” and “E” to Part change color!

At 1st I used lua script.Parent , but looks like that doesn’t work. So I tried



UserInputService.InputBegan:Connect(function(input, gameProccesedEvent)
	if input.KeyCode == Enum.KeyCode.Q then --The key that is pressed
		game.Workspace.Part.Color = Color3.new(0, 0.917647, 1)
	end
end)

UserInputService.InputBegan:Connect(function(input, gameProccesedEvent)
	if input.KeyCode == Enum.KeyCode.E then --The key that is pressed
		game.Workspace.Part.Color = Color3.new(0, 0.133333, 1)
	end
end)

But that doesn’t work either… I checked the console under the Client and Server tab and there is pretty much nothing… :frowning:

Method 1

You might wanna use this parameter.

if (not gameProcessedEvent) then
... -- Continue
end

Method 2

Try checking if the player is using a keyboard first!

if input.UserInputType == Enum.UserInputType.Keyboard then
... -- Continue code
end

Method 3

Try debugging your code. Enter a few print("Test1") codes throughout the script and see where it isn’t working.

If this is a server script, then try switching the code from the server script to the client script because UserInputService does not exist on the server.

It is under part. But hey i will try to put it in server script service.

Alright, tell me how it goes.

Sorry30Chars

So I added the print when the key is pressed as @LMVM2041 said and it looks like it’s not printing anything instead of some errors i have with plugins. I will try some more stuff brb

Try disabling some of your plugins, then.

I don’t really see how can that help me since errors are not coming from my script but i will try too.

1 Like

You can’t use LocalScripts in Workspace - put this in StarterPlayerScripts and it should work. If you want other players to see the color change, you will have to use RemoteEvents.

It wasn’t a local script none of this time

If you want to detect user input, you have to use a LocalScript. Scripts only run on the server, so UserInputService won’t work.

1 Like
local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(input, proc)
	if proc then
		return
	end
	if input.KeyCode == Enum.KeyCode.Q then --The key that is pressed
		game.Workspace.Part.Color = Color3.new(0, 0.917647, 1)
	end
end)

uis.InputBegan:Connect(function(input, proc)
	if proc then
		return
	end
	if input.KeyCode == Enum.KeyCode.E then --The key that is pressed
		game.Workspace.Part.Color = Color3.new(0, 0.133333, 1)
	end
end)

User input can only be detected in local scripts. I’ve also made use of the additional “game processed event” parameter, which stores a Boolean value which represents whether or not the input was processed by a core game feature, true if it was & false if it wasn’t, for example if the character “E” is inputted but was due to the player typing a chat message then the input is ignored and the function connected to the input event is instantly returned to prevent the rest of the function from executing.