Do any of you know how to play an animation on an NPC when you touch a certain block? If any of you know how this is done, please let me know. I know this isn't a request site, but this is important if I want to finish my game. Please help me if you know the answer.
COMMUNITY QUESTION
Touch Event to play an Animation with an NPC?
1 answer
Yeah, Sure, This should work:
local SP = script.Parent -- The Part To Be Stepped On
local Dummy = workspace.Dummy -- Change "Dummy" To Whatever You Want To Animate, Note* This Only Works Assuming That Your Only Animating One NPC
local Animation = Instance.new("Animation")
local Debounce = true -- Spam Detector
local LD = function(Parent, ID) Animation.Parent = Parent Animation.AnimationId = ID Dummy.Humanoid:LoadAnimation(Animation) end -- Loading Animation For Humanoid
SP.Touched:Connect(function(hit) -- "hit" Is The Part In Question. With This We Can Access The Player Who Stepped On The Block.
local Hit = hit.Parent
local AP = Dummy
wait(.5)
if Dummy:WaitForChild(Animation, 3) then -- Make Sure That There Is No Animation In Dummy
print("Animation Found In: "..AP.Name.."..Deleting..")
Animation:Destroy() -- Disonnecting Left Over Thread
else
print("No Animation Found In: "..AP.Name)
end
if Hit:WaitForChild("Humanoid", 3) and Debounce then
print("Found Humanoid From: "..Hit.Name.."!")
Debounce = false
LD(Dummy, "rbxassetid://AnimID") -- "AnimID" Change To Your Animation ID
wait(.5) -- Can Change Time For Debounce Reset
Debounce = true
else
print("Couldn't Find Humanoid From: "..Hit.Name.."....Or Debounce Is False")
end
end)
https://gyazo.com/303b1a1f4be62aef223908530f1fe23c -- Where You Should Put The Script
A Bit Over - Complicated But, this should be smooth.
Hope This Helped!
~Farsalis
This discussion is preserved as it was. New answers, comments, and votes are closed.
