Pausing animations

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.

Any suggestions?

Best,
Surgo

5 Likes

Are you sure adjusting speed doesn’t work?
If you check the api page, it says that adjusting speed to 0 should pause it.

"A positive value for speed plays the animation forward, a negative one plays it backwards, and 0 pauses it."

Could be a bug, but I’d check few more times before making bug report.
Posting code would help as well.

2 Likes

Yeah, i’m not sure what it is.

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)
3 Likes

Ah, yes!

I found that my animation will stop when the ROBLOX animation with the arms moving back and forward starts.

How can I get around this?

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:

a.Priority = Enum.AnimationPriority.NewPriority
3 Likes

How can I reverse this?

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)
1 Like

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)
18 Likes

How do I turn it back to default?

1 Like

You should be able to just call animation:AdjustSpeed() again.