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…
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.
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
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.
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.