Animation not playing on the player's character?

Hello I am Mario, I am trying to make a shift-to-sprint script and so far, with the fov tweening and the speed, its all working fine apart from the animation.

local tweenService = game:GetService("TweenService")

local hum = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local animation = hum:LoadAnimation(script.RunAnimation)


local info = TweenInfo.new(0.5)
local properties1 = {
	FieldOfView = 80,
}
local properties2 = {
	FieldOfView = 70,
}
local object = workspace.CurrentCamera

local IsRunning = script.IsRunning

uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		IsRunning.Value = true
		hum.WalkSpeed = 30
		local camTween = tweenService:Create(object, info, properties1)
		camTween:Play()
		
	end
end)

uis.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		IsRunning.Value = false
		hum.WalkSpeed = 16
		local camTween = tweenService:Create(object, info, properties2)
		camTween:Play()
	end
end)

hum.StateChanged:Connect(function(old,new)
	if IsRunning.Value == true then
		print("Running")
		if new == Enum.HumanoidStateType.Running then
			animation:Play()
			print("Definitely")
		else
			animation:Stop()
		end
	else
		animation:Stop()
	end
end)

This is the script I made, but the animation doesnt play. The checks that I put in, the print("Running") and print("Definitely") both print. Infact it only prints and plays the animation when im close to a particular dummy in workspace, yet I didnt code it to do that.

Hi there TheUnRealMario, a couple things regarding the animation. First off, ensure that:

  • The Animation is yours

  • The Animation’s Priority is set properly.

I know many Roblox tutorials inform you to use that method for loading in animations. I found a more reliable way to load animations. Here’s the code for it:
local character = script.Parent
local humanoid = character:WaitForChild(“Humanoid”)
local animator = humanoid:FindFirstChild(“Animator”)
local animation = Instance.new(“Animation”)
animation.AnimationId = “rbxassetid://IDHERE”
local animationTrack = animator:LoadAnimation(animation)
–This is a localscript located within StarterCharacterScripts

In terms of it only running when you’re near a dummy… it might just be coincidence. I hope this helps! Keep me updated!

I’ve seen someone post a problem similar to yours and I believe they solved the issue be reanimating or reexporting the animation. Unfortunately I can’t find that post at the moment. In addition to that, I would load the animation not to the humanoid, but to the Animator, which I believe can be found as a child instance of humanoid.

1 Like

The animation is mine, the priority is set to “Movement”

Try setting the priority to action.

1 Like

How can I do that though? I have seen it before but I forgot the way.

If you go to your animation editor, there should be 3 dots, “Set Animation Priority”. Select “Action” or “Idle”

1 Like

Yes I know how to do that, I set it to action just now

This would require you to re-export your animation although.

I did, It still didnt work. It only works when im close to the dummy i used to animate

You can also set it in the script, but I honestly don’t remember what the property name is.
Probably:
animation.Priority = Enum.AnimationPriority.Action
Not to sure though

1 Like

Try the script I used above… it’s more reliable.

1 Like

I found the post that had a similar issue, soneone found a solution to it.

If you don’t understand, the solution is basically just making your player the “owner” of all the BaseParts in you model.

1 Like

Animation weight
else
Animation Save as action
else
U can use movement detection with left shift checking

Hum:GetPropertyChangedSignal("MoveDirection"):Connect(function()
      if uis:IsKeyDown(Enum.KeyCode.LeftShift) then
         if Hum.MoveDirection.X ~= 0 or Hum.MoveDirection ~= 0 then
             if Anim.IsPlaying == false then
                 Anim:Play()
             end
         else
            Anim:Stop()
         end
      else
         if Anim.IsPlaying == true then
             Anim:Stop()
         end
      end
end)

That still doesnt solve the issue.

I could directly change the animate script’s animation IDs but it will be a tedious job and it’s unreliable.