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.
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)
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.
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. ;-;