Hello all, recently I’ve made this run script and another guy helped me with something, but I’m stuck on this topic.
How would i be able to make a jump animation, but it only activates when your running?
Source Code if you need it.
local uis = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local run = TweenService:Create(workspace.CurrentCamera, (TweenInfo.new)(0.5), {FieldOfView = 80})
local walk = TweenService:Create(workspace.CurrentCamera, (TweenInfo.new)(0.5), {FieldOfView = 70})
local playersHumanoid = game.Players.LocalPlayer.Character.Humanoid
--- Animation Creation
local newAnimation = (Instance.new)("Animation")
newAnimation.AnimationId = "rbxassetid://" .. script:GetAttribute("AnimationID")
loadAnimation = playersHumanoid:LoadAnimation(newAnimation)
-- Walkspeed Changing
local runSpeed = 25
local walkSpeed = 16
-- Variable
local PlayerIsRunning = false
(uis.InputBegan):Connect(function(Key)
if Key.KeyCode == (Enum.KeyCode).LeftShift then
run:Play()
loadAnimation:Play()
playersHumanoid.WalkSpeed = runSpeed
PlayerIsRunning = true
end
end)
uis.InputEnded:Connect(function(Key)
if Key.KeyCode == (Enum.KeyCode).LeftShift then
walk:Play()
loadAnimation:Stop()
playersHumanoid.WalkSpeed = walkSpeed
PlayerIsRunning = false
end
end)
playersHumanoid.Changed:Connect(function()
if playersHumanoid.Jump and loadAnimation.IsPlaying then
loadAnimation:Stop()
end
end)
playersHumanoid.StateChanged:Connect(function(oldState, newState)
if newState == (Enum.HumanoidStateType).Landed and PlayerIsRunning then
loadAnimation:Play()
end
end)
Don’t mind some of the code, i felt bored and used some dumb decompile website
You should use the animation’s weight property. Set it to a higher value than the default so that when a player walks, the animation starts. Or, a lower value so it plays when you’re idle.
playersHumanoid.StateChanged:Connect(function(oldState, newState)
if newState == Enum.HumanoidStateType.Landed and PlayerIsRunning then
loadAnimation:Play() -- Plays Run animation after a jump, if player is running.
elseif newState == Enum.HumanoidStateType.Jump and PlayerIsRunning then
loadRunJumpAnimation:Play() -- Plays Jump animation that will only appear in a jump, when the player is also running
end
end)
Make the “loadrunjump” animation have a higher priority. If you’re using Moon Animator, it should be in “Animation Settings”, if Roblox’s default animator, it’s in the File menu.
I don’t think you’ve read my reply correctly. What I was asking for is if you put the ID properly in that animation. An updated code snippet would help.
Yes, i did put it correctly. Here’s an updated code
local uis = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local run = TweenService:Create(workspace.CurrentCamera, (TweenInfo.new)(0.5), {FieldOfView = 80})
local walk = TweenService:Create(workspace.CurrentCamera, (TweenInfo.new)(0.5), {FieldOfView = 70})
local playersHumanoid = game.Players.LocalPlayer.Character.Humanoid
--- Animation Creation
local newAnimation = (Instance.new)("Animation")
newAnimation.AnimationId = "rbxassetid://" .. script:GetAttribute("AnimationID")
loadAnimation = playersHumanoid:LoadAnimation(newAnimation)
local runJumpAnim = (Instance.new)("Animation")
runJumpAnim.AnimationId = "rbxassetid://" .. script:GetAttribute("JumpID")
loadRunJump = playersHumanoid:LoadAnimation(newAnimation)
-- Walkspeed Changing
local runSpeed = 25
local walkSpeed = 16
-- Variable
local PlayerIsRunning = false
(uis.InputBegan):Connect(function(Key)
if Key.KeyCode == (Enum.KeyCode).LeftShift then
run:Play()
loadAnimation:Play()
playersHumanoid.WalkSpeed = runSpeed
PlayerIsRunning = true
end
end)
uis.InputEnded:Connect(function(Key)
if Key.KeyCode == (Enum.KeyCode).LeftShift then
walk:Play()
loadAnimation:Stop()
playersHumanoid.WalkSpeed = walkSpeed
PlayerIsRunning = false
end
end)
playersHumanoid.Changed:Connect(function()
if playersHumanoid.Jump and loadAnimation.IsPlaying then
loadAnimation:Stop()
end
end)
playersHumanoid.StateChanged:Connect(function(oldState, newState)
if newState == Enum.HumanoidStateType.Landed and PlayerIsRunning then
loadAnimation:Play()
elseif newState == Enum.HumanoidStateType.Jumping and PlayerIsRunning then
loadRunJump:Play()
end
end)
One more question. when the player stops walking and you’re still holding the shift button, the animation continues to play. Any info on that?
and when the player isn’t walking and u hold shift it plays.