-
What do you want to achieve? The “Idle” Animation will not stop after :Stop() is called
-
What is the issue? The Animation ignores the :Stop() call
-
What solutions have you tried so far? I’ve tried directly calling the stop method through Humanoid.Animator:GetPlayingAnimationTracks() will no success. All the other animations stop but not “Idle”
(This is for a Weapon)
Animation Controller
local animController = {}
--[[ANIMATIONS]]--
local AnimPath = script.Anims
local Anims = {
Reload = AnimPath.Reload;
Aim = AnimPath.Aim;
Idle = AnimPath.Idle;
Crouch = AnimPath.Crouch;
CrouchLooped = AnimPath.CrouchLooped;
}
local LoadedAnims = {}
--[[VARIABLES]]--
local Player
local Character
local Humanoid
function animController:PlayAnimation(animationName, Args)
local Looped = unpack(Args)
--// Check Variables
assert(type(Looped) == "boolean", "Looped must be a boolean value")
--// Search for the anim
local Anim
for _, v in pairs(LoadedAnims) do
if v.Name == animationName then
Anim = v
end
end
if Anim then
if Looped then
Anim.Looped = Looped
end
Anim:Play()
return(0)
else
error("Animation does not exist")
return(1)
end
end
function animController:StopAnimation(animationName)
--// Search for the anim
local Anim
for _, v in pairs(LoadedAnims) do
if v.Name == animationName then
Anim = v
end
end
if Anim then
Anim.Looped = false
Anim:Stop()
return(0)
else
error("Animation does not exist")
return(1)
end
end
function animController:StopAllAnimations()
for _, anim in pairs(LoadedAnims) do
local response = self:StopAnimation(anim.Name)
if response == 1 then
error("animController:StopAnimation() had an error")
end
end
end
function animController:CrossFade(animationToStop, animationToStart, Args)
local Looped, Weight, FadeTime = unpack(Args)
--// Check Variables
assert(type(Looped) == "boolean", "Looped must be a boolean value")
assert(type(Weight) == "number", "Weight must be a number value")
assert(type(FadeTime) == "number", "Looped must be a boolean value")
--// Search for the anim
local AnimToStop
local AnimToStart
for _, v in pairs(LoadedAnims) do
if v.Name == animationToStop then
AnimToStop = v
elseif v.Name == animationToStart then
AnimToStart = v
end
end
AnimToStart.Stopped:Connect(function()
self:PlayAnimation("Idle", table.pack(Looped))
end)
if AnimToStop and AnimToStart then
AnimToStop:AdjustWeight(Weight, FadeTime)
local response = self:PlayAnimation(animationToStart, table.pack(Looped))
self:StopAnimation(animationToStop)
if response == 1 then
error("Something failed with animController:CrossFade()")
end
else
error("Animation(s) does not exist")
return(1)
end
end
function animController:Init(player)
--// Init Global Variables
Player = player
Character = Player.Character
Humanoid = Character:FindFirstChild("Humanoid") or Character:WaitForChild("Humanoid")
--// Load Animations
for _, Anim in pairs(Anims) do
local LoadedAnim = Humanoid:LoadAnimation(Anim)
table.insert(LoadedAnims, LoadedAnim) --// Keep Track of All Animations
end
return
end
return animController
Gun Client
Tool.Equipped:Connect(function(Mouse)
if Humanoid.Health <= 0 then return end
--// Disable default idle animation
Character.Animate.idle.Animation1.AnimationId = "http://www.roblox.com/asset/?id=0"
Character.Animate.idle.Animation2.AnimationId = "http://www.roblox.com/asset/?id=0"
--// Play Aim Anim
AnimController:PlayAnimation("Aim", table.pack(true))
--// Check if the ShoulderCamera was enabled
if sCamEnabled then
ShoulderCamera:Enable()
AnimController:CrossFade("Aim", "Idle", table.pack(true, 1, 0.1))
end
--// Setup Gun Gui
GunGui.Enabled = true
AmmoFrame.GunName.Text = Tool.Name .." [" ..FiringMode.Value .."]"
AmmoFrame.AmmoCount.Text = "Ammo: " ..tostring(Ammo) .." / " ..tostring(ClipSize.Value)
--// Setup Mouse Icon
game:GetService("UserInputService").MouseIconEnabled = false
GunGui.GunIcon.Visible = true
GunGui.GunIcon.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y)
--// Equipped
Equipped = true
--// Setup Events
UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.LeftShift and not Reloading and not Firing and Equipped and not Crouched and sCamEnabled then
Sprinting = true
Event:FireServer("WalkspeedInc", 22)
elseif Input.UserInputType == Enum.UserInputType.MouseButton2 and Equipped and not Crouched and sCamEnabled then
Aiming = true
AnimController:CrossFade("Idle", "Aim", table.pack(true, 1, 0.1))
end
end)
UIS.InputEnded:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.LeftShift and not Crouched then
Event:FireServer("WalkspeedInc", 16)
Sprinting = false
elseif Input.UserInputType == Enum.UserInputType.MouseButton2 and Equipped and not Crouched and sCamEnabled then
Aiming = false
AnimController:CrossFade("Aim", "Idle", table.pack(true, 1, 0.1))
end
end)
Mouse.Move:Connect(function()
GunGui.GunIcon.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y)
end)
Mouse.KeyDown:Connect(function(Key)
if not Reloading and Key:lower() == "r" and Ammo ~= ClipSize and not Sprinting then
Reload(Mouse)
elseif Key:lower() == "z" and not isFirstPerson() and not PatrolMode then
if not sCamEnabled then
ShoulderCamera:Enable()
AnimController:CrossFade("Aim", "Idle", table.pack(true, 1, 0.1))
sCamEnabled = true
else
ShoulderCamera:Disable()
AnimController:CrossFade("Idle", "Aim", table.pack(true, 1, 0.1))
sCamEnabled = false
end
elseif not Reloading and Key:lower() == "v" and not Firing then
if FiringMode.Value == FiringModes[1] then
FiringMode.Value = FiringModes[2]
else
FiringMode.Value = FiringModes[1]
end
AmmoFrame.GunName.Text = Tool.Name .." [" ..FiringMode.Value .."]"
elseif Key:lower() == "c" then
if not Crouched then
Event:FireServer("WalkspeedInc", 0)
AnimController:CrossFade("Idle", "Crouch", table.pack(false, 1, 0.1))
wait(0.1)
AnimController:CrossFade("Crouch", "CrouchLooped", table.pack(true, 1, 0.01))
Crouched = true
else
Event:FireServer("WalkspeedInc", 16)
AnimController:CrossFade("CrouchLooped", "Crouch", table.pack(false, 1, 0.1))
wait(0.1)
AnimController:CrossFade("Crouch", "Idle", table.pack(true, 1, 0.1))
Crouched = false
end
elseif Key:lower() == "f" then
if not PatrolMode and not sCamEnabled then
AnimController:CrossFade("Aim", "Idle", table.pack(true, 1, 0.1))
PatrolMode = true
elseif PatrolMode and not sCamEnabled then
AnimController:CrossFade("Idle", "Aim", table.pack(true, 1, 0.1))
PatrolMode = false
end
end
end)
Mouse.Button1Up:Connect(function()
MouseDown = false
end)
Mouse.Button1Down:Connect(function()
MouseDown = true
if FiringMode.Value == "Auto" then
if not Firing and not Sprinting and Aiming then
while MouseDown and not Reloading and Ammo > 0 do
Firing = true
Ammo = Ammo - 1
AmmoFrame.AmmoCount.Text = "Ammo: " ..tostring(Ammo) .." / " ..tostring(ClipSize.Value)
Fire(Player:GetMouse(), 1)
Handle.Fire:Play()
wait(FireRate.Value)
end
Firing = false
end
else
if not Firing and not Reloading and Ammo > 0 and not Sprinting and Aiming then
Firing = true
Ammo = Ammo - 1
AmmoFrame.AmmoCount.Text = "Ammo: " ..tostring(Ammo) .." / " ..tostring(ClipSize.Value)
Fire(Player:GetMouse(), 1)
Handle.Fire:Play()
wait(FireRate.Value)
Firing = false
end
end
if Ammo <= 0 and not Firing and Aiming then
Handle.Empty:Play()
end
end)
end)
Tool.Unequipped:Connect(function()
AnimController:StopAllAnimations()
Equipped = false
GunGui.Enabled = false
if sCamEnabled then
ShoulderCamera:Disable()
end
if Crouched then
Event:FireServer("WalkspeedInc", 16)
end
game:GetService("UserInputService").MouseIconEnabled = true
Character.Animate.idle.Animation1.AnimationId = idleAnim1
Character.Animate.idle.Animation2.AnimationId = idleAnim2
end)
I genuinely have no clue where I’ve gone wrong.