Help with running animation starting, ending script

Hey there,

So, I managed to create my own running animation but, I’m stuck how to start it and how to stop it using a button. I put it in Replicated Storage/Animations/RunningAnimation.

So, I want to when I press “J” it activates the certain animation and when I press “J” it disactivates the running animation but, I do know part of the script but, I don’t know the other part of the script. I know that we should use " UserInputService" when making a button activates and disactivates.

it would help us to help you if you had a go at doing the scripting yourself and then asking for help if you get stuck.
There are loads of examples around so please do a search.

Happy new year!

I will only help you with part of the code, the rest try to figure it out. And only if you are stumped should you ask.

local UIS = game:GetService("UserInputService")
local Playing = false

UIS.InputBegan:Connect(function(Input)
    if Input.KeyCode = Enum.KeyCode.J then
        if Playing == false then
            Playing = true
            --Play Animation
        elseif Playing == true then
            Playing = false
            --Stop Animation
        end
    end
end)
1 Like

Yeah, that part I already know thx but, what I don’t know is the part where how do you make play animation, and stop animation in the script?

You can use :Play() and :Stop(), but you have to load the animation first.

Okay, thanks but, can I make it like this or do I change?image

Yes, you just have to reference the animation and do :Play() and :Stop()

I’m done,
This is the Code:

local UIS = game:GetService("UserInputService")
local Playing = false

UIS.InputBegan:Connect(function(Input)
    if Input.KeyCode = Enum.KeyCode.J then
        if Playing == false then
            Playing = true
            :Play(Run.RunAnim)
        elseif Playing == true then
            Playing = false
            :Stop(Run.RunAnim)
        end
    end
end)

So, the script I made didn’t work.

You have to use Run.Animation:Play()

Look I’m new to scripting so, could you plz be more specific where do I use it, etc.Also, thanks for still helping me, dude. :frowning:

local UIS = game:GetService("UserInputService")
local Playing = false

UIS.InputBegan:Connect(function(Input)
    if Input.KeyCode = Enum.KeyCode.J then
        if Playing == false then
            Playing = true
            Run.RunAnim:Play()
        elseif Playing == true then
            Playing = false
            Run.RunAnim:Stop()
        end
    end
end)

AnimTracks have the :Play() and :Stop() functions, to get the AnimTrack of your animation you have to call LoadAnimation upon your Humanoid you want it to Play on (in this case the LocalPlayer’s Character’s Humanoid) with the argument of your Animation Instance.

For example:

local LocalPlayer = game:GetService("Players").LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local AnimTrack = Humanoid:LoadAnimation(RunAnim)

--// To play it
AnimTrack:Play()
--// To stop it
AnimTrack:Stop()
2 Likes

Thanks! I really appreciate it. <3

1 Like

Ahh, totally forgot about it, I thought he already loaded it

1 Like