I want to achieve a tool that plays an animation on the first click then turns off the animation on the second click. The issue is the first click turns it on, but the second click won’t turn the animation off.
local tool = script.Parent
value = true
tool.Activated:Connect(function()
local humanoid = tool.Parent:FindFirstChild("Humanoid")
local Anim = tool.Parent.Humanoid:LoadAnimation(tool.Animation)
if value then
value = false
Anim:Play()
else
value = true
Anim:Stop()
end
end)
You load in a different animation every time you activate the tool a solution would be to load it outside
local tool = script.Parent
local value = true
local Anim
tool.Activated:Connect(function()
if not Anim then
local humanoid = tool.Parent:FindFirstChild("Humanoid")
Anim = tool.Parent.Humanoid:LoadAnimation(tool.Animation)
end
if value then
value = false
Anim:Play()
else
value = true
Anim:Stop()
end
end)