Animation not stopping?

Hello,

So I have a run function and a run animation, and one problem with it is that whenever the player stops running, the animation does not stop. (idk how to fix this)
Here’s the portion of the script:

  ["Run"] = function(isRunning) 
		local humanoid: Humanoid = char:WaitForChild("Humanoid")
		local Tween = game:GetService("TweenService")
		local camera: Camera = workspace.CurrentCamera
		local event: RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild(" "):WaitForChild("RunEvent")
		local info = TweenInfo.new(
			.8,
			Enum.EasingStyle.Bounce,
			Enum.EasingDirection.Out,
			0,
			false,
			0
		)
		local animator: Animator = humanoid:WaitForChild("Animator")
		local animation = Instance.new("Animation")
		animation.AnimationId = 'https://www.roblox.com/asset/?id=13060081719'
		local run_track: AnimationTrack = animator:LoadAnimation(animation)
		if isRunning then
			run_track:Play()
			local goals = {}
			goals.FieldOfView = 90
			local track = Tween:Create(camera, info, goals)
			track:Play()
			event:FireServer(isRunning, humanoid)
		else
			local goals2 = {}
			goals2.FieldOfView = 70
			local track = Tween:Create(camera, info, goals2)
			track:Play()
			event:FireServer(isRunning or false, humanoid)
			run_track:Stop()
		end
	end,

Help is appreciated.

2 Likes
run_track.Priority = Enum.AnimationPriority.Action4

You must set the priority of your animation higher than the basic one:

["Run"] = function(isRunning) 
	local humanoid: Humanoid = char:WaitForChild("Humanoid")
	local Tween = game:GetService("TweenService")
	local camera: Camera = workspace.CurrentCamera
	local event: RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild(" "):WaitForChild("RunEvent")
	local info = TweenInfo.new(
		.8,
		Enum.EasingStyle.Bounce,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	local animator: Animator = humanoid:WaitForChild("Animator")
	local animation = Instance.new("Animation")
	animation.AnimationId = 'https://www.roblox.com/asset/?id=13060081719'
	local run_track: AnimationTrack = animator:LoadAnimation(animation)
	run_track.Priority = Enum.AnimationPriority.Action4
	if isRunning then
		run_track:Play()
		local goals = {}
		goals.FieldOfView = 90
		local track = Tween:Create(camera, info, goals)
		track:Play()
		event:FireServer(isRunning, humanoid)
	else
		local goals2 = {}
		goals2.FieldOfView = 70
		local track = Tween:Create(camera, info, goals2)
		track:Play()
		event:FireServer(isRunning or false, humanoid)
		run_track:Stop()
	end
end,

I forgot to reply, the solution is up here.

It stills continues to play even after I sprint…

Can you add print(isRunning) after run_track.Priority = Enum.AnimationPriority.Action4 to see what is the reaction?

It prints true when I sprint, and false when I stop sprinting.

There are a error or not? in the output

There’s no errors at all…chrrr

You can’t fire a Remote Event with a instance, Right?

event:FireServer(isRunning or false, humanoid)

Yes you can… you can fire a remote event with anything except dictionaries I think

Oh ok, my bad.
Can you Put run_track:Stop() up to local goals2 = {}?

Nope, didnt work.

limtixmzcxzcharrr

Can you put print("is not running") before local goals2 = {} to see?

The print statement works

chhrhrrr

Replace the print('is not running") to print(run_track) to see if run_track is nil

It just prints Animation… its not nil