I have this script right here:
--// Sit Animation
local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local mouse = player:GetMouse()
local Sitanim = Instance.new("Animation")
Sitanim.AnimationId = "http://www.roblox.com/asset/?id=2519769373" -- id of animation
isAnim = false
script.Parent.MouseButton1Click:connect(function()
if isAnim == false then
local playSitAnim = humanoid:LoadAnimation(Sitanim)
playSitAnim:Play()
isAnim = true
end
if isAnim == true then
local playSitAnim = humanoid:LoadAnimation(Sitanim)
playSitAnim:Stop()
isAnim = false
end
end)
I am trying to set "isAnim" to true or false to be able to "turn on" the animation and "turn it off" so I will be able to stop the animation when I want. But this doesnt seems to work. There are no errors.

13 comments
This doesn`t works. humanoid is a nil value.
Forgot to add that in lol. You will also need to add in the correct logic for when the player respawns but that depends on where this local script is located.
You will need a CharacterAdded event to assing the new humanoid object to the variable humanoid.
Its a gui button, its located in StarterGUI. Also what do you mean when player respawns?
You only account for when the player first spawns. When they die and respawn a new character is created. You just need to find the newly created humanoid as assing it to the variable so that your code will work correctly when the player dies.
Oh, thanks I got it. But one thing, when I am pressing the button, nothing happens. The animation wont play.
no errors btw
Are there any errors?
Nope, just a button that doesn`t works when you click on it.
Just had to invert the logic so that IsPlaying would stop else play. I have also changed the id so that I can get it working.
Thanks man. It works :D. Also if I want the animation to "work" more slowly do I have to add more seconds in the animation editor? Like, if I want the character to sit slowly, for example..
The function Play allows you to specify the speed specify https://www.robloxdev.com/api-reference/function/AnimationTrack/Play :Play(0.1, 1, [speed]) The speed is a % so 2 will be *2 speed.
There is also a AdjustSpeed function if you want to set it in one place. Then just use :Play() as normal.