So I have an eating animation that I want to play when I tool is activated. But the animation is not playing. The script is a server Script inside of StarterCharacterScripts amd there are no errors in the output bar.
Code
--Animation variables
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local Animation = Humanoid:LoadAnimation(script:WaitForChild("Animation"))
local isRunning = false
--Tool variables
local Tool = game.ReplicatedStorage.Food["Cake slice"]
local HealthPoints = 100
--Code
Tool.Activated:Connect(function()
if not isRunning and not HealthPoints == 0 then
isRunning = true
Animation:Play()
else
isRunning = false
Animation:Stop()
HealthPoints = HealthPoints - 10
end
end)
local animator = humanoid:FindFirstChildOfClass("Animator")
if animator then
local animationTrack = animator:LoadAnimation(animation)
animationTrack:Play()
end