Hello! I recently wanted to make a game, when i noticed i cant script a part to trigger a NPC animation. So i wanted to know, How can u make ur NPC or model play a animation on part touch? Then make it so it goes to different parts like a walking AI, then when a player hits another part, it stops the whole animations. Thanks!
You have to give us more information to help you with this.
Do you have any code already? Such as, are you already detecting a part being touched?
Does your npc already have an animation script that it uses to animate it walking?
If none of those, you might need to read up on these topics.
https://create.roblox.com/docs/reference/engine/classes/BasePart#Touched
local Part = workspace.Part
local NPC = workspace.NPC
local Animator = Instance.new("Animator")
Animator.Parent = NPC.Humanoid
local Animation = Instance.new("Animation")
Animation.AnimationId = "your animation id"
Animation.Parent = game.ReplicatedStorage
Part.Touched:Connect(function()
NPC.Humanoid:FindFirstChildOfClass("Animator"):LoadAnimation(Animation):Play()
end
this should work. Remember to place the âyour animation idâ with your actual animationid with the rbxasset stuff and switch the NPC with your NPC.
are you sure this actually works? Also how do i make it so it can go to different trigger parts after the animation played?
What do you mean by this� And it does work if you correctly fill in the things.
Ok, let me give u more information. So im trying to remake the Doorâs seek chase where he comes out of the floor and starts running except i have done the animations and like in Doors, seeks chase is triggered by a part. So i want the animation to play and then make him go to different parts and then when a player touches a different part, the animation ends
Iâm not sure if playing an animation yields the thread, but if it doesnât, simply place a delay (The length of the animation track) and then do all the property manipulation on other parts after.
Ok what im trying to do actually, is i want it so when a player touches a trigger part, the animation plays and then the npc uses pathfinding AI to go to different parts, and then when another trigger part is touched, the whole animation ends.
Use the Stop function on the loadanimation once the player triggers the end animation part. Use pathfinding service PathfindingService | Roblox Creator Documentation.
Sorry, but i donât really know how to fit all that in a single script. Else it might get loads of errors and warnings.
I donât know your level of scripting experience, but this might be more than your level. Donât think that I am saying that you shouldnât try things and learn by doing, because you absolutely should, but maybe start off with smaller things, and work your way up to do something like you are asking.
Such as, first get comfortable with hitting triggers, then move on to moving things, then later to playing animations.
That being said, I have recently on here answered posts, that used the type of elements you are needing for this.
Here are some links.
Like @SelDraken said, learn all the basics. Itâs clear you have not learned all the basics yet.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.