Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
4

Is there a way to stop all animations?

Asked by
gitrog 326 Moderation Voter
7 years ago

So, I wrote a few animation scripts, but, when you load in one animation, it plays "on top of" another animation, leading to... unusual results. How would I stop all animations playing before I start a new animation? This is one of my animation scripts as an example.

local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=789576867"
local animTrack = nil

function onChatted(message, player)
    if message == "/e sit" then
        local character = game.Workspace[player.Name]
        animTrack = character.Humanoid:LoadAnimation(animation)
        animTrack:Play()
    end
end

game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message) onChatted(message, player) end)
end)

2 answers

Log in to vote
8
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

You can use Humanoid:GetPlayingAnimationTracks(), which will return a table that contain all active animation tracks. You can then loop over that with a for loop, and call Stop() on every animTrack.

Example:

local Humanoid = game.Players.LocalPlayer.Character.Humanoid
local ActiveTracks = Humanoid:GetPlayingAnimationTracks()
for _,v in pairs(ActiveTracks) do
    v:Stop()
end
0
How do i stop a certain animation track though Cmonlol135 5 — 6y
0
@Cmonlol135 All you would have to do is find the name that you named the Animation and just add this in: if v.Name =='ANIMATIONNAME' then v:Stop() KardashevScale 110 — 6y
0
Does this work anymore? And if it does how do I make the button cancel ALL of the animations? Pyro_dood 31 — 4y
0
it still works and to make a butt just put lines 3 to 5 in a script.Parent.MouseButton1Click:connect(function() CatastrophicDinosaur 4 — 3y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You could make a Boolvalue that inserts into the player like this (Make this a LocalScript and then put it in StarterPack also put a BoolValue into the local script and name it whatever, i named it active as seen in the example below:

local player = game.Players.LocalPlayer
while wait(1)do
if script.Active.Value == false then
script.Active.Value = true
local f = Instance.new("BoolValue")
f.Name = "AnimActive"
f.Value = false
f.Parent = player.Character
wait(.1)
end
end

Then you want to do this:

function onChatted(message, player)
    if message == "/e sit" and player.Character.AnimActive.Value == false then
player.Character.AnimActive.Value = true
        local character = game.Workspace[player.Name]
        animTrack = character.Humanoid:LoadAnimation(animation)
        animTrack:Play()
wait(.3)
player.Character.AnimActive.Value = false
    end
end

You can make it go to false after playing the anim OR make a different script for when the player jumps it will go to false. The AnimActive insert bool value script will reset when player dies so dont worry about that Do this for every anim script and they wont run unless that anim active value = false To do the player jump makes the anim active value false do this copy the insert anim active value script rename it and replace the code inside with this code V:

local player = game.Players.LocalPlayer
local x1 = player.Character:WaitForChild("AnimActive")
while wait(.00000001)do
if script.Active.Value == false and x1.Value == true and player.Character.Humanoid.Jump == true then
x1.Value = false
wait()
end
end

This will detect if player has jumped or not and disable the value if they have then you can play a new animation if its false. Hope this helps, Kyu.

0
This is over a year old, and this question already had an accepted answer... gitrog 326 — 6y
0
Yes, that may be how old this question is however u asked: "How do i stop a certain animation track though" and I thought this might be helpful KyuketsukiZero 3 — 6y
0
Continuation to my comment: U asked that 23 days ago thats not too long if you really think about it. KyuketsukiZero 3 — 6y

Answer this question