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