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