Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Ending Animations with a button?

Ive managed to make a button that when pressed makes you show a sitting animation, but i cant get it to stop. im fine with either clicking again to stop or a seperate button.

Animation-https://www.roblox.com/library/5582851387/Sit-1

Code:

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://5582851387"

local trackanimation = nil
local playability = true

function playAnimation (animationSource)
	if playability == true then
		local plr = game.Players.LocalPlayer
		trackanimation = plr.Character.Humanoid:LoadAnimation (animation)
  
		trackanimation.KeyframeReached:connect (function()
			print('hi')
   
		end)
		trackanimation:Play()
	end
end
script.Parent.MouseButton1Click:Connect(playAnimation)


3 comments

0

idk why the code pasted weird

0
0

yes but i dont know how to tie it into a button

2 answers

You can use GetPlayingAnimationTracks to find the animation track and stop it. Example:

local Dummy = workspace:WaitForChild("Dummy") -- Lets say there's a dummy in workspace

local Tracks = Dummy.Humanoid:GetPlayingAnimationTracks() -- Returns a table

for i,v in pairs(Tracks) do
if v.Name == "name of your sitting animation" then
v:Stop() -- Stops that animation
end
end

1 comment

0

i dont know how to put my animation i already made onto a dummy

Just do trackanimation:Stop() when you want to stop the animation from playing.

1 comment

0

how would i make it so that when you click the emote button again it stops

This discussion is preserved as it was. New answers, comments, and votes are closed.