There are multiple error in your code.
First of all, you're getting OnServerEvent on ReplicatedStorage, not a RemoteEvent. In my revised working code below, I created a Remote Event in ReplicatedStorage called "punchingEvent".
Also, you were trying to get "KeyDown" on a Mouse, not a keyboard. You should use UserInputService for this, and use "InputBegan". When the input begins, you can check if it was a key, and what key they pressed. Then, the "q" should be Enum.KeyCode.Q because the KeyCode is an Enum.
Lastly, AnimationID isn't a valid member of animation, it's AnimationId. It's case sensitive.
FYI: You can get character from the player object, you don't have to find it in workspace.
That error you received was from a plugin you had installed, not your code, unless your code is a plugin.
It gave me an error because I don't own the animation, but I hope you do so you can run it!
Here's the revised code:
Animation (ServerScriptService) Script
game.ReplicatedStorage.punchingEvent.OnServerEvent:Connect(function(player, animationID)
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID"..animationID
local loadedAnimation = player.Character.Humanoid:LoadAnimation(animation)
loadedAnimation:Play()
end)
Controls (StarterGui) Local Script
local UIS = game:GetService'UserInputService'
UIS.InputBegan:connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
local keyPressed = input.KeyCode
if keyPressed == Enum.KeyCode.Q then
game.ReplicatedStorage.punchingEvent:FireServer(01900686745)
end
end
end)
I hope this helped!
1 comment
you forgot an = after the ID but I fixed it anyway