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

How to animate a custom npc?

Asked by 8 years ago
Edited 8 years ago

I have tried several scripts to put the animation controller inside of the model including local and regular scripts. No matter what i do, the npc does not play the animation i made using the animation editor, yes i have a humanoidrootpart, a head, and a torso. Please help, i need to figure this out in order to continue the game im making. Im not asking for a full script, i just need to know what im doing wrong, ill post the script im using if needed. Thanks in advanced

0
Do you have a umanoid? PreciseLogic 271 — 8y
0
Yea codyn6263 5 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

Greetings , i'll probably need you to post a few pictures of how you're setting the humanoid up , i'll also need the script , but before doing so , try getting this in the Humanoid/Model (You need an Animation controller just if it's not an humanoid , i believe you can just load the animation in the humanoid directly)

function onTouched(Part)
if Part.Parent:FindFirstChild("Humanoid") and Part.Parent.Name ~= script.Parent.Name then
local Torso = script.Parent:WaitForChild("Torso")
 local Anim = game.ReplicatedStorage.Animations:WaitForChild("YourAnimation") -- This is just an example , i don't know where you have your anim.
local Human = script.Parent:FindFirstChild("Humanoid")
local YourAnimation = Human:LoadAnimation(Anim)
YourAnimation:Play()
end

Torso.Touched:connect(onTouched) -- This script would play any animation once you've touched the torso of your npc.
0
THANK YOU THAT WORKED!! codyn6263 5 — 8y
0
Pm me if you need something else , it may be faster. Fabiox99 25 — 8y
0
Alright thanks man! codyn6263 5 — 8y
Ad
Log in to vote
0
Answered by 8 years ago
while wait() do
    local Torso = script.Parent:WaitForChild("Torso") --Wait for the torso
    local Anim = game.Workspace.Animations:WaitForChild("Anim") --Path to your animation
    local Human = script.Parent:FindFirstChild("Humanoid") --Wait for the humanoid
    local YourAnimation = Human:LoadAnimation(Anim) --Load the animation into the humanoid
    YourAnimation:Play() --Play the animation
    wait(3) --Wait 3 seconds
end

In case someone stumbles upon this in the future and doesnt understand. This will constantly loop your animation just to test it, if you dont want it to loop, just remove the while wait() do. A big thank you to Fabiox99 for supplying the answer.

Answer this question