Loading Animation Doesn't Play + Aiming Animation Doesn't Stop

I’m making my first weapon/tool so things aren’t going too smooth. Basically I want the gun to play the Idle Animation the second you equip it (obviously) and upon pressing F, if you have not done so already it will play a load animation then continue afterwards to an aiming animation. It’s sort of working half and half, the Idle Animation will play upon equipping the gun but once you press F it does run the line of code that tells it to play the Loading animation but it doesn’t show on the character. Oh and once you un-equip the weapon your still stuck in the aiming animation.

My code:

    local InputService = game:GetService("UserInputService")

    local Tool = script.Parent.Parent
    local CoolDown = false
    local Equipped = false
    local Aiming = false
    local Loaded = false
    local Plr = game.Players.LocalPlayer




    Tool.Equipped:Connect(function()
    	Equipped = true
    	
    	-- Animations
    	local Idle = Tool.Assets.Animations.IdleAnimation
    	IdleAnim = Plr.Character.Humanoid:WaitForChild("Animator", 3):LoadAnimation(Idle)
    	local Aim = Tool.Assets.Animations.AimAnimation
    	AimAnim = Plr.Character.Humanoid:WaitForChild("Animator", 3):LoadAnimation(Aim)
    	local Load = Tool.Assets.Animations.AimAnimation
    	LoadAnim = Plr.Character.Humanoid:WaitForChild("Animator", 3):LoadAnimation(Load)
    	
    	
    	if Equipped then
    		IdleAnim:Play()
    	end
    	
    	InputService.InputBegan:Connect(function(Input, Received)
    		if Input.UserInputType == Enum.UserInputType.MouseButton1 and not CoolDown and Equipped then
    			CoolDown = true
    			
    			print("clicked")
    			
    			CoolDown = false
    			
    		elseif Input.UserInputType == Enum.UserInputType.Keyboard then
    			if Input.KeyCode == Enum.KeyCode.F then
    				if not Loaded then
    					print("loaded")
    					LoadAnim:Play()
    					
    					LoadAnim.Stopped:Wait()
    					
    					Loaded = true
    				end
    					
    				if Loaded then
    					if Aiming == false then
    						Aiming = true
    						AimAnim:Play()

    					elseif Aiming == true then
    						Aiming = false
    						AimAnim:Stop()
    					end
    				end
    			end
    		end
    	end)
    end)



    Tool.Unequipped:Connect(function()
    	IdleAnim:Stop()
    	AimAnim:Stop()
    	LoadAnim:Stop()
    	Equipped = false
    end)

EDIT: Fixed the aiming animation not stopping but I still am unable to figure why the loading animation won’t play.

1 Like

Try this to stop the Idle animation.

Tried it already, didn’t do a thing. Also the animation priority of the Loading Animation is set higher so by default it should player over it anyways.

Maybe you should try to stop the LoadAnim and IdleAnim first bc if it is played,it will bother other animation that you want it to play.

So let’s break the lines down to here maybe

    			if Input.KeyCode == Enum.KeyCode.F then
    				if not Loaded then
    					print("loaded")
    					LoadAnim:Play()
    					
    					LoadAnim.Stopped:Wait()
    					
    					Loaded = true
    				end
    					
    				if Loaded then
    					if Aiming == false then
    						Aiming = true
    						AimAnim:Play()

    					elseif Aiming == true then
    						Aiming = false
    						AimAnim:Stop()
    					end
    				end
                end

You said it prints when it’s not Loaded, maybe add another print statement to double-check that the LoadAnim variable is actually playing?

Yes it is playing. I made the place active if you want to see it in-game, 2 - Roblox

1 Like

I’ve actually discovered a pattern with the gun. You equip it, press “F” then it goes to the loading animation and your stuck there. Unequip it then equip it again then you press “F” and you can freely switch between aiming and idle, but if you unequip and reequip it again it goes back to the first time.

So the animation just stays playing & stuck like that is from what I’m understanding? :thinking:

I think there might be something wrong with the animation itself or something. As I figured out that the Aiming animation isn’t where it is staying, it only plays the first part of the Loading animation which is the same as the aiming, if that makes sense.

Maybe you could be overriding the animations the wrong way?

oh my gosh… well I think I figured out the issue…

local Load = Tool.Assets.Animations.AimAnimation

I told the “Load” variable to use the “AimAnimation” instance instead of the “LoadAnimation”…

O h

Ah yes repeated mistakes

At least the issue is fixed though hopefully!

Yeah, that’s true, but I already hit my next issue lmao.