Is it possible to run a animation every time somebody runs and jumps?If yes how?
Is animation possible to script?
1 answer
Yes it is. There are functions in the humanoid called Running and Jumping or you can change the default animations
Before we look at the methods I must make sure you know how to get your animation id! (if you do just please scroll past this.) Step1:Export your animation Step2:go to animation and get the id numbers in the url Step3:Done! Anyway...
Method 1 (Changing Default Animations!) If you want to do it the simple and easy way we just need to get the animate from player! In a local script we first get the player variables.
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.Character:Added()
local animate = character:WaitForChild("Animate")
--Now we set the id's
animate.walk.WalkAnim.AnimationId = "rbxassetid://YOUR ID NUMBERS HERE"
animate.jump.JumpAnim.AnimationId = "rbxassetid://YOUR ID NUMBERS HERE"
--AND THAT IS IT :D
Method 2 (Using the Running and Jumping function from humanoid to get the animations!)
if we connect these we can make events to run an animation but first we will need a local script.
wait(1) -- first I add this here just to make sure the player loaded.
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.Character:Added()
local humanoid = character:WaitForChild("Humanoid")
--Before we make the script we will have to get the player variables,
--Now we make the animation function.
function playAni(Ani) --Ani will be used for our current animation
local animTrack = humanoid:LoadAnimation(Ani) --this will load the animation used in the function
animTrack:Stop() --first we stop the animation
wait(.1) --wait a sec then
animTrack:Play() --this will play our current animation.
end
--We have completed the function! now we must make the animations
local RunningAnimation = Instance.new("Animation") --This adds our animation
local JumpingAnimation = Instance.new("Animation")
RunningAnimation.AnimationId = "rbxassetid://YOUR ID NUMBERS HERE"
JumpingAnimation.AnimationId = "rbxassetid://YOUR ID NUMBERS HERE"
--Next we make a debounce to stop the running animation from looping when running
local CanNotPlayRun = false
--Now we make a running and jumping function!
function onRunning(speed) --we will need speed to tell if we are moving!
if speed > 1 then
if CanNotPlayRun == false then
CanNotPlayRun = true --we set it to true so it will not rapidly play it
playAni(RunningAnimation) --Now we can play our running animation using that function!
end
elseif speed < 1 then --now we can set the debounce to false again when speed == 0
CanNotPlayRun = false
end
end
function onJumping()
playAni(JumpingAnimation) --Now we play the jumping animation on this function!
end
humanoid.Running:connect(onRunning) --This gets our humanoid functions!
humanoid.Jumping:connect(onJumping)
Oh and put the local scripts in either starterpack or startergui! that is all. If this helped please accept! ~KIheros :) (I may have made errors on this as this was not tested.)
This discussion is preserved as it was. New answers, comments, and votes are closed.
