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.
How to play an animation for a Non-Player Character with AnimationController from LocalScript?
1 answer
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
6 comments
Thanks for your answer, but it wasn't helpful. I need something, some way to allow me play animations from LocalScripts, I already know other parts like Keypress or playing an animation.
For short, I need a suggestion. But still, thanks for your effort.
I've tried, you can't.
I would recommend doing your best to discourage the use of deprecated members like KeyDown as much as possible.
Alright.
I thought animations could ONLY be played through LocalScripts.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
The animation has to be played on the server. Using remote events, the client can tell the server to tell the humanoid to play the animation.