Animation stops when i press a movement key

I wana be able to make it so when i play an animation it doesent get canceld out by the Animate script

Ive tried adding the animation name to the ignore function but it didnt work. The over animations priority is action4

The animate script:

-- local Debris = game:GetService("Debris")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

local plr = game.Players.LocalPlayer
local character = plr.Character
local humanoid = character:WaitForChild("Humanoid")
local root = character:WaitForChild("HumanoidRootPart")
local animator = humanoid:WaitForChild("Animator")

local lastFootstepSound = nil
local animTracks = {}
local transitionTime = 0.2
local jumpAnimTime = 0
local holdingTool = false

local function StopAllAnimations(ignoreName)
	for i, animTrack in pairs(animator:GetPlayingAnimationTracks()) do
		if animTrack.Name == ignoreName 
			or (ignoreName == "Run" and animTrack.Name == "Walk")
			or (holdingTool and animTrack.Name == "Tool") then 
			continue 
		end
		animTrack:Stop(transitionTime)
	end
end

local function AdjustAnimation(name, speed, weight)
	animTracks[name]:AdjustSpeed(speed)
	animTracks[name]:AdjustWeight(weight)
end

local function PlayAnimation(name, speed, weight)
	animTracks[name]:Play(transitionTime)
	AdjustAnimation(name, speed, weight)
	StopAllAnimations(name)
end

local function Running(speed)
	if speed > 0.5 then	

		local relativeSpeed = speed / 16
		local runAnimWeight, walkAnimWeight = 0.001, 0.001

		if relativeSpeed < 1.2 then 
			-- Walking speed
			walkAnimWeight = 1	
		elseif relativeSpeed < 0.9 then
			-- Blend run and walk
			local fadeInRun = (relativeSpeed - 0.5)/(1 - relativeSpeed)
			walkAnimWeight = 1 - fadeInRun
			runAnimWeight  = fadeInRun
			relativeSpeed = 1
		else
			-- Simply run
			runAnimWeight = 1
		end

		if animTracks["Run"].IsPlaying then
			if speed > 1 then
				AdjustAnimation("Walk", relativeSpeed, walkAnimWeight)
				AdjustAnimation("Run", relativeSpeed, runAnimWeight)	
			end
		else
			PlayAnimation("Walk", relativeSpeed, walkAnimWeight)
			PlayAnimation("Run", relativeSpeed, runAnimWeight)
		end
	else
		PlayAnimation("Idle")
	end
end

local function Jumping()
	jumpAnimTime = 0.31
	PlayAnimation("Jump")
end

local function Falling()
	if (jumpAnimTime <= 0) then
		PlayAnimation("Fall")
	end
end

local function Climbing(speed)
	if speed == 0 then
		if not animTracks["Run"].IsPlaying then
			AdjustAnimation("Climb", 0, 1)
		end
	else
		local relativeSpeed = speed / 5
		if animTracks["Climb"].IsPlaying then
			AdjustAnimation("Climb", relativeSpeed, 1)
		else
			PlayAnimation("Climb", relativeSpeed)
		end

	end
end

local function Swimming(speed)
	if speed > 1 then
		local relativeSpeed = speed / 10
		if animTracks["Swim"].IsPlaying then
			AdjustAnimation("Swim", relativeSpeed, 1)
		else
			PlayAnimation("Swim", relativeSpeed)
		end
	elseif not animTracks["SwimIdle"].IsPlaying then
		PlayAnimation("SwimIdle", 1)
	end
end

function LoadAnimations()
	local animationIDs = {
		Climb = "rbxassetid://10921257536",
		Fall = "rbxassetid://10921262864",
		Idle = "rbxassetid://16764671325",
		Jump = "rbxassetid://10921263860",
		Run = "rbxassetid://16764719676",
		Walk = "rbxassetid://16764790194",
		Swim = "rbxassetid://10921264784",
		Tool = "rbxassetid://507768375"
	}


	for name, id in pairs(animationIDs) do
		local animation = Instance.new("Animation")
		animation.AnimationId = id
		local track = animator:LoadAnimation(animation)
		animTracks[name] = track
		animTracks[name].Name = name

	end
	
	animTracks["Idle"]:Play()

	humanoid.Running:Connect(Running)
	humanoid.Jumping:Connect(Jumping)
	humanoid.FallingDown:Connect(Jumping)
	humanoid.FreeFalling:Connect(Falling)
	humanoid.Climbing:Connect(Climbing)
	humanoid.Swimming:Connect(Swimming)
end

LoadAnimations()

RunService.Heartbeat:Connect(function(deltaTime)
	if (jumpAnimTime > 0) then
		jumpAnimTime = jumpAnimTime - deltaTime
	end

	local tool = character:FindFirstChildOfClass("Tool")
	if tool and tool:FindFirstChild("Handle") then
		holdingTool = true
		if not animTracks["Tool"].IsPlaying then
			animTracks["Tool"]:Play(transitionTime)
		end
	else
		holdingTool = false
		animTracks["Tool"]:Stop(transitionTime)
	end
end)
2 Likes

Nvm figured it out just had to change the ignor table and it worked

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.