Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to play an animation for a Non-Player Character with AnimationController from LocalScript?

Asked by 7 years ago

Please include the code which you are trying to use, so the community will be better-equipped to help you with your problem.

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.

0
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. AZDev 590 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

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

0
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. superalp1111 662 — 7y
0
For short, I need a suggestion. But still, thanks for your effort. superalp1111 662 — 7y
0
I've tried, you can't. User#15927 0 — 7y
0
I would recommend doing your best to discourage the use of deprecated members like KeyDown as much as possible. OldPalHappy 1477 — 7y
View all comments (2 more)
0
Alright. User#15927 0 — 7y
0
I thought animations could ONLY be played through LocalScripts. antonio6643 426 — 7y
Ad

Answer this question