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

How do I make it so when a player touches a certain part,an animation is played on an NPC?

Asked by 4 years ago
Edited 4 years ago

I want to make it so when I touch a certain part,an animation plays in a certain npc. I found a script on the web but I don't know how to use it or if it is right. Btw I'm terrible at scripting.

local part = --write here
local animation = --write here
local animationTrack = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(animation)

part.Touched:connect(function(p)
    if game.Players:GetPlayerFromCharacter(p.Parent) = game.Players.LocalPlayer then
        animationTrack:Play()
        --add more code
    end
end)

1 answer

Log in to vote
0
Answered by 4 years ago

First: Create a Part and an Animation in your workspace.

Replace your script for this(Its like the one you posted but it works for NPCs(Yours Works for players))


local part = game.Workspace.Part local animation = game.Workspace.Animation animation.AnimationId = "http://roblox.com/Asset?ID=467504759" part.Touched:Connect(function() local animationTrack = game.Workspace.NPC.Humanoid:LoadAnimation(animation) animationTrack:Play() end)

You can change the animation ID at line 3 for the ID of the animation of your choice(I made one as a sample, you can use it if you want to)

You can replace the word "NPC" at line 6 for the name of your NPC.

Now just touch the part.Here ill send some results:

Before touching it: http://prntscr.com/qdecl5

After touching it(Couldn't make a video sry): http://prntscr.com/qded0p

Contact me if you have any issues with the script.

0
Thank you very much! If you have time, how do I make it debounce? PhacYouBeech 17 — 4y
0
Im sorry i dont get it, what exactly do you mean with debounce? kevinsoaresv 47 — 4y
0
It like glitches out when I move on the block PhacYouBeech 17 — 4y
View all comments (3 more)
0
Oh, now i get it.Try replacing this script with the one i sent you: https://pastebin.com/UCbNh3c8 You can change the number at line 12, it is the amount of time you have to wait until you can make the npc do the animation again. kevinsoaresv 47 — 4y
0
Thank you man, very much appreciated. PhacYouBeech 17 — 4y
0
No problem, Have a nice day! kevinsoaresv 47 — 4y
Ad

Answer this question