i have multiple connections to a table for animations.
when the disconnect function runs, the animation will still play at the end (1)
in other words, when i unequip the animation to return to the equipped animation still runs
local LoadedAnimations = {}
local connections = {}
local Animations = {
script:WaitForChild("Hold"),
script:WaitForChild("Idle"),
script:WaitForChild("Click"),
script:WaitForChild("Reload"),
script:WaitForChild("Aim")
}
tool.Equipped:Connect(function()
local char = player.Character
local hum = char:WaitForChild("Humanoid")
local Aim = false
local idle = false
local Reload = false
local Unequipped = true
-- Animations to humanoid
LoadedAnimations[1] = hum:LoadAnimation(Animations[1])
LoadedAnimations[2] = hum:LoadAnimation(Animations[2])
LoadedAnimations[3] = hum:LoadAnimation(Animations[3])
LoadedAnimations[4] = hum:LoadAnimation(Animations[4])
LoadedAnimations[5] = hum:LoadAnimation(Animations[5])
-- play defualt
LoadedAnimations[1]:Play()
--Died
connections[1] = hum.Died:Connect(function()
DisconnectAll()
end)
connections[5] = UserInputService.InputBegan:Connect(function(Input,GPE)
if GPE then return end
if Input.KeyCode == Enum.KeyCode.R then
if Reload == false then
Reload = true
StopOtherAnimations(4)
LoadedAnimations[4]:Play()
wait(tonumber(Configuration.ReloadDelay.Value/2))
particleemiter.Enabled = true
wait(tonumber(Configuration.ReloadDelay.Value/2))
particleemiter.Enabled = false
LoadedAnimations[4]:Stop()
LoadedAnimations[1]:Play()
Reload = false
end
end
end)
end)
tool.Unequipped:Connect(function()
particleemiter.Enabled = false
StopOtherAnimations(0)
DestroyFolderItems(LoadedAnimations)
DisconnectAll()
end)
video of what happening
robloxapp-20221216-1208103.wmv (1.1 MB)
(accidently clicked enter before typing everything on devfourm, sry)