I apologize if I have this structured incorrectly.
I am having a bit of trouble figuring out how to “pause” my animations. The issue I am running into is when I play an animation, it will run through its time, then bring the character back to the regular idle stance. For example, I created an animation for kneeling down. When I play this animation, it will play the animation for the character kneeling, then, right after the character will go back to idle (stopping the animation).
Is there any way I can pause an animation from running any further?
I tried using :AdjustSpeed(0), but this didn’t seem to work.
Maybe there’s another ROBLOX animation thats overriding it? Idle animation?
Here’s the script I was using:
local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
Anim = script.Animation
Mouse.KeyDown:connect(function(key)
if key == "t" then
local a = player.Character.Humanoid:LoadAnimation(Anim)
a:Play()
wait(2)
a:AdjustSpeed(0)
end
end)
What are the priority levels of your animations? Perhaps you’d like to look into using a higher priority. All Roblox animations use the Core priority, with a few overriding movements (iirc only Jump) use the Idle priority. Setting your animation to a higher priority level may dismiss this.
You can either change the priority in the Animation Editor or via a line of code at run time:
How can I stop my animation from running and go back to normal ROBLOX animations? I am currently stuck playing mine.
I tried changing the priority back to Core but that seems to do nothing. I also tried stopping it but that didn’t do anything as well.
Thanks for the help!
wait(1)
local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
salutekey = "t"
saluteid = script.Salute
salute = false
Mouse.KeyDown:connect(function(key)
if key == salutekey then
print(salute)
if salute == false then
salute = true
local a = player.Character.Humanoid:LoadAnimation(saluteid)
a:Play()
a.Priority = Enum.AnimationPriority.Idle
wait(2)
a:AdjustSpeed(0)
else
local a = player.Character.Humanoid:LoadAnimation(saluteid)
a:Stop()
a.Priority = Enum.AnimationPriority.Core
salute = false
end
end
end)
You’ll have to include your loaded animation as an upvalue. Whenever the KeyDown event runs, it references a new AnimationTrack every time.
-- No need to have a wait, LocalPlayer is implicitly available to LocalScripts
local player = game:GetSerivce("Players").LocalPlayer -- GetService is canonical
local Mouse = player:GetMouse() -- Consider changing to UserInputService sometime
local salutekey = "t" -- Use local variables
local saluteid = script.Salute -- Same here
local saluting = false -- Use clear variable names
local saluteanim = player.Character.Humanoid:LoadAnimation(saluteid)
-- ^ Need a few checks in the future such as if player exists, if player has humanoid, etc
saluteanim.Priority = Enum.AnimationPriority.Idle -- Consider setting from Animation Editor
Mouse.KeyDown:Connect(function (key) -- connect is deprecated for Connect
if key == salutekey then
print(saluting) -- Keep for debugging only
saluting = not saluting -- Awesome way to flip a variable
if saluting then
saluteanim:Play()
wait(2) -- Consider a debounce so this isn't overridden
saluteanim:AdjustSpeed(0)
else
saluteanim:Stop() -- Use fade parameter if you want arms to go slowly down
-- No need to change the priority level to Core
end
end
end)