Dear Developers,
I am currently trying to make a healing potion, that makes an animation when used but stops if the player moves or unequipped it.
How can I detect if it stopped naturally because the animation ended (so it restores HP) or if it has been stopped because the player moved (or unequipped it), so it won’t restore any HP?
local tool = script.Parent
local anim = tool.Handle.Animation
local db = true
tool.Activated:Connect(function()
local humanoid = tool.Parent:FindFirstChild("Humanoid")
if humanoid and db then
local playAnim = humanoid:LoadAnimation(anim)
playAnim:Play()
humanoid.WalkSpeed = 0
wait(0.1)
humanoid.WalkSpeed = 17
db = false
humanoid.Running:connect(function(speed)
if speed > 10 and speed < 17 then
playAnim:Stop()
end
end)
playAnim.Stopped:Connect(function()
db = true
end)
tool.Unequipped:Connect(function()
playAnim:Stop()
end)
end
end)