Answered by
4 years ago Edited 4 years ago
As you said, you want to fire the event on Keyboard key press (I assume), but you have an incomplete code.
Instead of:
1 | game:GetService( "UserInputService" ).InputBegan:Connect( function (key) |
4 | game:GetService( "UserInputService" ).InputBegan:Connect( function (input) |
And the lines I am gonna add next will make sure that the key from keyboard is pressed and not a Mouse button or something.
1 | if input.UserInputType = = Enum.UserInputType.Keyboard then |
If you want to know the key that is pressed, you can create a local variable for that:
1 | local PressedKey = input.KeyCode |
Extra Info: If you wanna fire the event on specific key press, you can do:
1 | if PressedKey = Enum.KeyCode.E then |
This is how it will look in your code (Commented the extra info script):
1 | game:GetService( "UserInputService" ).InputBegan:Connect( function (input) |
2 | if input.UserInputType = = Enum.UserInput.Type.Keyboard then |
3 | local PressedKey = input.KeyCode |
5 | script.Parent.ServerKeyboard:FireServer(PressedKey) |
Lemme know if it helps!