local player = game.Players.LocalPlayer repeat wait() until player.Character.Humanoid local humanoid = player.Character.Humanoid local mouse = player:GetMouse()
local anim = Instance.new("Animation") anim.AnimationId = "http://www.roblox.com/asset/?id=(animationid)"
mouse.KeyDown:connect(function(key) if key == "r" then local playAnim = humanoid:LoadAnimation(anim) playAnim:Play() game:GetService("StarterGui"):SetCore("ResetButtonCallback", false) game.StarterPlayer.EnableMouseLockOption = false game.StarterPlayer.AutoJumpEnabled = false game. wait(3.2) game:GetService("StarterGui"):SetCore("ResetButtonCallback", true) game.StarterPlayer.EnableMouseLockOption = true game.StarterPlayer.AutoJumpEnabled = true end end)
It plays the animation, but Roblox, when you are not moving, plays an idle animation, and that idle animation makes the animation stop, and then plays the idle animation.
So everytime Roblox plays an idle animation, the animation stops. How do I fix this?
(And the id=(animationid) is my animation id. )
Animation stopped by Roblox idle animations, what to do?
Before we can get to the solution we should probably discuss why this is not working. The issue is because ROBLOX has something called an Animation Priority system. This means animations with higher priority are played over those with lower priority.
There is an Enum
for all animation priorities; Enum.AnimationPriority
. Ranking them by lowest to highes (1 is lowest, 4 is highest):
Derived from: https://developer.roblox.com/en-us/api-reference/enum/AnimationPriority
Your animation likely has a priority lower or equal to Idle. If you want the animation to not get stopped by Idle animations then you will want to use priorities above Idle such as Movement and Action.
You can set the Priority
property of an AnimationTrack
to change its priority during run time; you can also change the priority through the Animation Editor Plugin provided by ROBLOX.
In this case it is just easier to change the Priority
property of your AnimationTrack
. If you don't know which variable is your AnimationTrack
then look for the :LoadAnimation
method. This method returns an AnimationTrack
instance.
local playAnim = humanoid:LoadAnimation(anim)
On this line you have humanoid:LoadAnimation(anim)
therefore playAnim
is an AnimationTrack
.
Therefore you can do something like this:
local playAnim = humanoid:LoadAnimation(anim) playAnim.Priority = Enum.AnimationPriority.Action playAnim:Play()