Animations not working?

This is the animation


However, when I play and even though it’s printing “Play sniff” the animation does not actually play

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")

local Player = Players.LocalPlayer
local Character = Player.Character

local Sniff = script:WaitForChild("Sniff")

local LoadSniff = Character.Humanoid:LoadAnimation(Sniff)


-- Mouse click started
local function InputBegan(input, GPE)
	if GPE then return end
	
	if input.UserInputType ~= Enum.UserInputType.MouseButton2 then return end
	print("Play sniff")
	LoadSniff:Play()
end

UserInputService.InputBegan:Connect(InputBegan)

First you must ensure that it has a higher priority level than the rest of the animations playing.
Second you may want to try to play it on a server script in case the first assumption does not work.

There are no other animations playing. Since I’m using a custom character, none of Roblox’s default animations play.

Humanoid:LoadAnimation() is deprecated. Use Humanoid.Animator:LoadAnimation() (but make sure to create a new animator instance or check to see if it exists first)

1 Like

Pretty sure I’m supposed to use AnimationController | Documentation - Roblox Creator Hub but same thing. Nothing happens when loading animation to that

Major problem is that… if you are refering to local player, you need

game.Players.LocalPlayer

instead of Players.LocalPlayer

Bruh what!? :face_with_raised_eyebrow:

Please read the script. Top line

local Players = game:GetService("Players") 

So

local Player = Players.LocalPlayer

Works

No different than doing

game.Players.LocalPlayer

Except Players is a service. Thus if you wanna write clean code, should reference it at the top of the script :upside_down_face:

1 Like

yeah I just notice you put that in the script, thats why i deleted

I don’t know if you’re experiencing the same issue, but I am having a problem similar to this as well. The problem relates to an error displaying that ‘Animator is not a descendant of game object’, when I wait for the character, and I wait for the character to be parented.

Try making a certain key on your keyboard(example: Use F) that triggers that animation. So it will be like:

local db = false
UIS.InputBegan:Connect(function(input, GPE)
    if input.KeyCode == Enum.KeyCode.F and not db then
        db = true
        animation:Play()
        animation.Finished:Wait() — please correct me if I use the event which indicates the animation is done playing is correct or not.
        db = false
    end
end)

Try it and test.

Is your game a group game or profile? If it’s profile, is it created to your profile? If it’s group, is the animation on the group that the game’s on?

Both game and animation are under my profile

animation.Completed:Wait() -- unsure if 'Finished' is a method.

Is it looped?

Yes it is looped

Does the roblox debugger show anything irregular? If so can you mention it?

Your issue is from the code you gave us would be because your animation is overriding itself. Since the play animation is not in the if statement of “MouseButton2” it the play animation is playing when you start moving or any other keybind related action. ;-;

Thank you. I will take your words.