As you said, you want to fire the event on Keyboard key press (I assume), but you have an incomplete code.
Instead of:
game:GetService("UserInputService").InputBegan:Connect(function(key)
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.
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:
local PressedKey = input.KeyCode
Extra Info: If you wanna fire the event on specific key press, you can do:
if PressedKey = Enum.KeyCode.E then
This is how it will look in your code (Commented the extra info script):
game:GetService("UserInputService").InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInput.Type.Keyboard then
local PressedKey = input.KeyCode
script.Parent.ServerKeyboard:FireServer(PressedKey)
end
end)
Lemme know if it helps!