You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I’m making animations for my tools in my roblox game.
What is the issue? Include screenshots / videos if possible!
The animations don’t feel right when I’m actually playing them and aren’t properly stopping when I unequip the tool, leading to other animations being broken.
What solutions have you tried so far? Did you look for solutions on the Creator Hub?
ChatGPT
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
You load a new animation each time the tool is equipped and used, causing the original ones to never stop, as well as constantly overwriting the same variable which could cause some animations to never be able to be stopped.
Load the animations once at the top of the script.
--// Get variables (Animation loading should be done in a LocalScript)
local player = game.Players.LocalPlayer
local character = Player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
--// Loading animations on the Humanoid is deprecated, use the Animator.
local animator = humanoid :WaitForChild("Animator")
--// Load the animations ONCE.
local equippedAnim = animator:LoadAnimation(script:WaitForChild("Equip"))
local holdAnim = animator:LoadAnimation(script:WaitForChild("Hold"))
local activatedAnim = animator:LoadAnimation(script:WaitForChild("Drink"))
--// To easily avoid memory leaks
local connections = {}
--// Adjust values for animations if needed.
holdAnim.Looped = true
--// Create animation binds outside the connections to avoid memory leaks.
table.insert(connections,
equippedAnim.Ended:Connect(function()
holdAnim:Play()
end)
)
--// Rest of your code but well, without reloading the animations.
table.insert(connections,
script.Parent.Equipped:Connect(function()
equippedAnim:Play()
end)
)
table.insert(connections,
script.Parent.Activated:Connect(function()
activatedAnim:Play()
activatedAnim:AdjustSpeed(2)
end)
)
table.insert(connections,
script.Parent.Unequipped:Connect(function()
holdAnim:Stop()
activatedAnim:Stop()
equippedAnim:Stop()
end)
)
table.insert(connections,
humanoid.Died:Connect(function()
for _, con in connections do
con:Disconnect()
end
table.clear(connections) --// Unsure if this is needed, better to be safe than sorry.
end)
)