Hi, I know nothing about scripting so help would be appreciated.
What do you want to achieve?
I want my NPC to play an animation when I click on it then animation stops after the animation stops playing then when I click on it again it will play the animation again.
What is the issue?
I don’t have an issue about this to be honest.
What solutions have you tried so far?
I tried looking at the dev forum but I can’t seem to find topics similar to mine same goes for YouTube.
try adding ClickDetector on the torso or upper torso of whatever on the NPC
and add a script inside the click detector. now add animation on the script
and then edit the script and should be like:
local NPC = script.Parent.Parent.Parent -- the npc
local Humanoid = NPC:FindFirstChild("Humanoid") -- the npc's humanoid
local Animation = script:WaitForChild("Animation") -- the animation
script.Parent.MouseClick:Connect(function()
if Humanoid ~= nil then
Humanoid:LoadAnimation(Animation)
end
end)
dont know if this really works though… i directly typed this here
this can make the npc repeatedly play the animation. this is better:
local isPlaying = false
local animTime = 10 -- replace with how long the animation is
local NPC = script.Parent:WaitForChild("NPC")
local Hum = NPC:FindFirstChild("Humanoid")
local Anim = script:WaitForChild("Animation")
local DetectorPart = script.Parent:WaitForChild("ClickPart")
local ClickDetector = DetectorPart.ClickDetector
local LoadAnim = Hum:LoadAnimation(Anim)
ClickDetector.MouseClick:Connect(function()
if isPlaying == true then
print("Already Playing")
elseif isPlaying == false then
isPlaying = true
LoadAnim:Play()
wait(animTime)
isPlaying = false
end
end)
Bam. Error
Infinite yield means it can wait forever
it think that the clickdetector is parented to itsself
make sure you add an extra .Parent to the clickdetector variable