Hey there, thanks for stopping by to help me!
So I am using Fe gun kit to make my FPS game, and I added a sprint animation by following this tutorial: Sprinting Animations Tutorial Update (FOR OLDER VERSIONS) - YouTube and I came across this small problem, which is that whenever I am idle, I can press left-shift and the sprint animation plays. And a another thing is that when I jump, i can press left-shift and the sprint animation plays.
What do you want to achieve? Stop playing the sprint animation when idle or jumping.
What solutions have you tried so far? I have searched and visited other similar problems like mine, but they couldn’t help.
Here is my script(A code snippet of the GunScript_Local):
TempMouse.KeyDown:connect(function(Key)
if string.lower(Key) == "r" then
Reload()
elseif Key.Keycode == Enum.KeyCode.LeftShift then
if not Reloading and ActuallyEquipped and Enabled and not HoldDown and Module.HoldDownEnabled then
HoldDown = true
if not VMHoldDownAnim.IsPlaying then
VMIdleAnim:Play()
end
if AimIdleAnim and AimIdleAnim.IsPlaying then AimIdleAnim:Stop() end
if IdleAnim and IdleAnim.IsPlaying then IdleAnim:Stop() end
if VMIdleAnim and VMIdleAnim.IsPlaying then VMIdleAnim:Stop() end
if HoldDownAnim then HoldDownAnim:Play(nil,nil,Module.HoldDownAnimationSpeed) end
if VMHoldDownAnim then VMHoldDownAnim:Play(nil,nil,Module.VMHoldDownAnimationSpeed) end
local UIS = game:GetService("UserInputService") -- get it
UIS.InputBegan:Connect(function(input,ischatactive)
if ischatactive then return end -- determines if chat or the menu is open or closed
if input.KeyCode == Enum.KeyCode.R --[[the "R" is your keycode change it with one that pleases you]] then
-- do yo stuf
end
end)
local Humanoid = -- get the humanoid
TempMouse.KeyDown:connect(function(Key)
if string.lower(Key) == "r" then
Reload()
elseif Key.Keycode == Enum.KeyCode.LeftShift then
if not Reloading and ActuallyEquipped and Enabled and not HoldDown and Module.HoldDownEnabled then
HoldDown = true
if not VMHoldDownAnim.IsPlaying and Humanoid.MoveDirection == Vector3.new(0,0,0) and Humanoid:GetState() ~= Enum.HumanoidStateType.Freefall and Humanoid:GetState() ~= Enum.HumanoidStateType.Jumping and Humanoid:GetState() ~= Enum.HumanoidStateType.Landing then
VMIdleAnim:Play()
end
if AimIdleAnim and AimIdleAnim.IsPlaying then AimIdleAnim:Stop() end
if IdleAnim and IdleAnim.IsPlaying then IdleAnim:Stop() end
if VMIdleAnim and VMIdleAnim.IsPlaying then VMIdleAnim:Stop() end
if HoldDownAnim then HoldDownAnim:Play(nil,nil,Module.HoldDownAnimationSpeed) end
if VMHoldDownAnim then VMHoldDownAnim:Play(nil,nil,Module.VMHoldDownAnimationSpeed) end
fix my spelling errors if any cuz wrote it in forum
local Humanoid = -- get the humanoid
TempMouse.KeyDown:connect(function(Key)
if string.lower(Key) == "r" then
Reload()
elseif Key.Keycode == Enum.KeyCode.LeftShift then
if not Reloading and ActuallyEquipped and Enabled and not HoldDown and Module.HoldDownEnabled then
HoldDown = true
if not VMHoldDownAnim.IsPlaying and Humanoid.MoveDirection == Vector3.new(0,0,0) and Humanoid:GetState() ~= Enum.HumanoidStateType.Freefall and Humanoid:GetState() ~= Enum.HumanoidStateType.Jumping and Humanoid:GetState() ~= Enum.HumanoidStateType.Landed then
VMIdleAnim:Play()
end
if AimIdleAnim and AimIdleAnim.IsPlaying then AimIdleAnim:Stop() end
if IdleAnim and IdleAnim.IsPlaying then IdleAnim:Stop() end
if VMIdleAnim and VMIdleAnim.IsPlaying then VMIdleAnim:Stop() end
if HoldDownAnim then HoldDownAnim:Play(nil,nil,Module.HoldDownAnimationSpeed) end
if VMHoldDownAnim then VMHoldDownAnim:Play(nil,nil,Module.VMHoldDownAnimationSpeed) end
All of them? So all of this code has to be written to “~=”:
if not VMHoldDownAnim.IsPlaying and Humanoid.MoveDirection == Vector3.new(0,0,0) and Humanoid:GetState() == Enum.HumanoidStateType.Freefall and Humanoid:GetState() == Enum.HumanoidStateType.Jumping and Humanoid:GetState() == Enum.HumanoidStateType.Landing then
VMIdleAnim:Play()
end
And if you think that script error has to do something to do with my error:
local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local character = Player.Character
local movespeed
character.Humanoid.Running:Connect(function(run)
movespeed = run
if run == 0 then
if PlayAnim and PlayAnim.IsPlaying then
PlayAnim:Stop()
character.Humanoid.WalkSpeed = 17.5 -- Base Walk Speed
end
end
UIS.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift and movespeed ~= 0 then -- Stops animation from playing while idle
local Anim = Instance.new('Animation')
print("ran")
character.Humanoid.WalkSpeed = 30 -- Sprint Speed
for i,v in pairs(character:GetChildren()) do
if v:IsA("Tool") then
if v:FindFirstChild("GunScript_Server") then
Anim.AnimationId = v.Sprint.AnimationId
end
end
end
PlayAnim = workspace.Camera.Arms.Animation:LoadAnimation(Anim) -- Loops aniamtion
PlayAnim.Looped = true
PlayAnim:Play()
end
end)
UIS.InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
character.Humanoid.WalkSpeed = 17.5
PlayAnim:Stop()
end
end)