Hello developers!
I’m currently trying to achieve an item that plays an animation and restore up an value when players uses it. But, for some reason, the function on Animation.Ended isn’t running
local debounce = false
script.Parent.Activated:Connect(function()
if debounce == false then
debounce = true
local anim = script.Animation
local track = script.Parent.Parent:FindFirstChildWhichIsA("Humanoid"):FindFirstChildWhichIsA("Animator"):LoadAnimation(anim)
script.Parent.BottleBottom["Metal Drinking Fountain 14 (SFX)"]:Play()
track:Play()
track.Ended:Connect(function()
print("ksmaks")
local plr = game.Players.LocalPlayer
local sanity = plr:WaitForChild("Sanity")
if sanity.Value >= 60 then
sanity.Value = 100
print("Ksksksks sanity1 ")
else
print("Sanity +40")
sanity.Value += 40
end
task.wait(.1)
print("Destroyed")
script.Parent:Destroy()
end)
end
end)