I have a script that plays an animation when you equip a Bloxy Cola
but I don’t know how to stop the animation after it’s unequipped I don’t know how to do this but I’ve tried one thing but it didn’t work.
This is the script:
local Tool = script.Parent;
local plr = script.Parent.Parent.Parent
local opened = script.Parent.opened
enabled = true
function onActivated()
if not enabled then
return
end
if opened.Value == true then
enabled = false
Tool.Handle.DrinkSound:Play()
Tool.Parent.Humanoid:LoadAnimation(Tool.drink):Play()
task.wait(5)
enabled = true
end
end
enabled = true
function onEquipped()
if opened.Value == false then
Tool.Parent.Humanoid:LoadAnimation(Tool.equip):Play()
Tool.Handle.OpenSound:play()
task.wait(1)
opened.Value = true
end
end
script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)
local Tool = script.Parent
local plr = script.Parent.Parent.Parent
local opened = script.Parent.opened
enabled = true
track = nil
function onActivated()
if not enabled then
return
end
if opened.Value == true then
enabled = false
Tool.Handle.DrinkSound:Play()
Tool.Parent.Humanoid:LoadAnimation(Tool.drink):Play()
task.wait(5)
enabled = true
end
end
enabled = true
function onEquipped()
if opened.Value == false then
if not track then track = Tool.Parent.Humanoid:LoadAnimation(Tool.equip):Play() end
Tool.Handle.OpenSound:play()
task.wait(1)
opened.Value = true
end
end
function onUnequipped()
if track then track:Stop() end
end
script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)
script.Parent.Unequipped:connect(onUnequipped)
Took your script, combined with other replier’s scripts and furthermore modified it a myself, tested it in studio myself and everything worked perfectly for me. Scripts you received before this one should’ve also worked but try this anyway and let me know how it works for you.
-- Script
local tool = script.Parent
local player = tool.Parent.Parent
local opened = tool.opened
local enabled = true
local equipTrack -- 'equipTrack' - currently equal to 'nil' but will reference the 'equip' animation later on.
local drinkTrack -- 'drinkTrack' - like 'equipTrack', currently equal to 'nil' but will reference the 'drink' animation later on.
function onActivated()
if not enabled then -- If 'enabled' variable is 'false', return.
return
end
if opened.Value then -- If 'Value' property of 'opened' is 'true', set & play 'drink' animation.
enabled = false
tool.Handle.DrinkSound:Play()
if drinkTrack == nil then
drinkTrack = tool.Parent.Humanoid:LoadAnimation(tool.drink)
drinkTrack:Play()
else
drinkTrack:Play()
end
task.wait(5)
enabled = true
end
end
function onEquipped()
if not opened.Value then -- If 'Value' property of 'opened' is 'false', set & play 'equip' animation or just play 'equip' animation.
tool.Handle.OpenSound:Play()
if equipTrack == nil then
equipTrack = tool.Parent.Humanoid:LoadAnimation(tool.equip)
equipTrack:Play()
else
equipTrack:Play()
end
task.wait(1)
opened.Value = true
end
end
function onUnequipped()
if drinkTrack ~= nil then -- If 'drinkTrack' variable isn't equal to 'nil', stop playing what it's equal to.
drinkTrack:Stop()
end
if equipTrack ~= nil then -- If 'equipTrack' variable isn't equal to 'nil', stop playing what it's equal to.
equipTrack:Stop()
end
end
tool.Activated:connect(onActivated)
tool.Equipped:connect(onEquipped)
tool.Unequipped:Connect(onUnequipped)