Animation doesnt stop

Hello, Im trying to make a gun run system with anims. But for some reason the anim doesnt stop.
Any suggestions on how to fix it?

local function GunRun(PlayOrStop)
	for i, v in pairs(Character:GetChildren()) do
		if v:IsA("Tool") then
			local animation1 --= Humanoid:LoadAnimation(v:FindFirstChild("AnimsFolder").Run) 
			local animation2 --= Humanoid:LoadAnimation(v:FindFirstChild("Animations").Run) 
			if v:FindFirstChild("Animations") then
				animation2 = Humanoid:LoadAnimation(v:FindFirstChild("Animations").Run) 
			end
			if v:FindFirstChild("AnimsFolder") then
				animation1 = Humanoid:LoadAnimation(v:FindFirstChild("AnimsFolder").Run) 
			end
			if PlayOrStop == "Play" then
			if v:FindFirstChild("AnimsFolder") then --or v:FindFirstChild("Animations") then
				if v:FindFirstChild("AnimsFolder").Run then
					animation1:Play()
				end
			elseif v:FindFirstChild("Animations") then
				if v:FindFirstChild("Animations").Run then
					animation2:Play()
				end
			end
		elseif PlayOrStop == "Stop" then
			if v:FindFirstChild("AnimsFolder") then --or v:FindFirstChild("Animations") then
					if v:FindFirstChild("AnimsFolder").Run then
					animation1:Stop()
				end
			elseif v:FindFirstChild("Animations") then
					if v:FindFirstChild("Animations").Run then
					animation2:Stop()
				end
			end
		end
	end
end
end

Each time you’re running its loading a new animation. Try loading the Animations out of the function.

Im not sure how id find the animations outside the function, The animations is located in the tool that you currently have equipped.

Does this work?

local animation1
local animation2
local function GunRun(PlayOrStop)
	for i, v in pairs(Character:GetChildren()) do
		if v:IsA("Tool") then
			if v:FindFirstChild("Animations") and not animation2 then
				animation2 = Humanoid:LoadAnimation(v:FindFirstChild("Animations").Run) 
			end
			if v:FindFirstChild("AnimsFolder") and not animation1 then
				animation1 = Humanoid:LoadAnimation(v:FindFirstChild("AnimsFolder").Run) 
			end
			if PlayOrStop == "Play" then
			if v:FindFirstChild("AnimsFolder") then --or v:FindFirstChild("Animations") then
				if v:FindFirstChild("AnimsFolder").Run and animation1 then
					animation1:Play()
				end
			elseif v:FindFirstChild("Animations") then
				if v:FindFirstChild("Animations").Run and animation2 then
					animation2:Play()
				end
			end
		elseif PlayOrStop == "Stop" then
			if v:FindFirstChild("AnimsFolder") then --or v:FindFirstChild("Animations") then
					if v:FindFirstChild("AnimsFolder").Run and animation1 then
					animation1:Stop()
				end
			elseif v:FindFirstChild("Animations") then
					if v:FindFirstChild("Animations").Run and animation2 then
					animation2:Stop()
				end
			end
		end
	end
end
end

No the animation is still playing

Edited, re-try it.

It works, thank you for helping :smile:

1 Like