Animation Priority problems

Hi, i have little problem with setting animation priority. In animation editor i set it to Core but then when i test my game id doesn’t work. I run, jump and anim is still playing.
This is script used to launch animation. (Changing priority by script doesn’t work too.)
Could you help me?

game.ReplicatedStorage.RemoteEvents.InGameEvents.Animation.OnServerEvent:Connect(function(player,animationId)
	
	local animation = Instance.new("Animation")
	animation.AnimationId = animationId
	local animationTrack = player.Character.Humanoid:LoadAnimation(animation) 
	animationTrack:Play()
	animationTrack.Stopped:Connect(function()
		animation:Destroy()
	end)
end)

If im not wrong Core is like, the lowest priority and basically gets overwritten by everything, since changing priority by code doesnt seem to be working you could try reuploading the animation with the priority set to Action

You are totally right! But there is one problem, i want this animation to STOP when i do anything else, not to keep playing :confused:

perhaps reupload the animation with its priority set to idle? and I also think animations run better on on a localscript, and they also replicate to the server so you dont have to worry about sending it over a remote event

Try defining the LoadAnimation above the function.

Every time you load an animation you create a new track copy of it.

Problem.



bla.bla.bla:Connect(function(result)

local myAnimation = humanoid:LoadAnimation(myAnimationLocation) --/!!/  NO!

		if result == "true" then
            --/!!/  Is going to play a whole new LoadAnimation thread you defined inside the function
			myAnimation:Play()
		else
			myAnimation:Stop()
            --/!!/  Won't stop because you defined a whole new LoadAnimation
		end
end)

Fix.

local myAnimation = humanoid:LoadAnimation(myAnimationLocation) --/!!/  YES!
    
bla.bla.bla:Connect(function(result)
	
	--/delete/  local myAnimation = humanoid:LoadAnimation(myAnimationLocation)
		
		if result == "true" then
			myAnimation:Play()
		else
			myAnimation:Stop()
		end
end)

It didn’t work, i put this to local script and tried every - core, idle, movement and action, still nothing :confused:

There is one problem, animation ID changes…

local userInput = game:GetService("UserInputService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://3303391864"
animation.Parent = script
local track = animator:LoadAnimation(animation)
track.Priority = Enum.AnimationPriority.Action

local animationToggle = false

local function onHumanoidMoved()
	if humanoid.MoveDirection.Magnitude > 0 then
		track:Stop()
	end
end

local function onInputDetected(inputObject, wasProcessed)
	if wasProcessed then return end
	
	if inputObject.KeyCode == Enum.KeyCode.E then
		animationToggle = not animationToggle
		if animationToggle then
			track:Play()
		else
			track:Stop()
		end
	end
end

humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(onHumanoidMoved)
userInput.InputBegan:Connect(onInputDetected)

This is just an example script but it clearly exemplifies how animations should be loaded and prioritised then played and stopped when necessary.

1 Like

Thank you!
Most useful were those lines

local function onHumanoidMoved()
	if humanoid.MoveDirection.Magnitude > 0 then
		track:Stop()
	end
end

It works perfectly right now, thanks!