Well, my script does not gives error, just does not play animation for NPC. Since AnimationController cannot be used with Humanoid and since animations for NPC cannot be loaded from a LocalScript, how can I play animation for that NPC? If you ask why it has to be LocalScript, NPC plays an animation as I press a key, so for KeyPress, I have to use LocalScript.
To answer your question, you can't use LocalScript, you must use a server-side script,
The difference between a LocalScript and a server-side script is that local scripts can access client-only objects, for example a camera, server-side scripts can use the server, such as players.
First, you must know the LoadAnimation method, to use this method you must select a humanoid.
player = game:GetService("Players").LocalPlayer wait(1) animation = player.Character.Humanoid:LoadAnimation(animation location) animation:Play()
To make a character animate on KeyDown
--My keydown deprecated script player = game:GetService("Players").LocalPlayer mouse = player:GetMouse() mouse.KeyDown:connect(function(mouse) if key == "q" then local animation = player.Character.Humanoid:LoadAnimation(animation location) animation:Play() end end) --My keydown that is not deprecated script --I'm new to do this. function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.--put the key here then local animation = player.Character.Humanoid:LoadAnimation(animation location) animation:Play() end end game:GetService("UserInputService").InputBegan:connect(onKeyPress) --Choose which one.
However, I can tell you something extra.
There is something called Motor6Ds, you can animate them if you would like to.
Link: http://wiki.roblox.com/index.php?title=API:Class/Motor6D
Some of these scripts were made in the text of scriptinghelpers, please give me the errors in developer console if it doesn't work, or goes wrong. If it goes wrong then do this line of code.
wait(animation time) animation:Stop()
~Sincerely CLVRB