Roblox Sprinting

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.

  1. What do you want to achieve? Stop playing the sprint animation when idle or jumping.

  2. 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

Please don’t hesitate to ask any questions!

Meant2Win

2 Likes

use UserInputService

How? Can you be more specific?

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)
1 Like

Ok, but using UserInputService fix my original problem?

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

1 Like

The error still occurs, and yes I did check the output.

what error do you get? in the output

1 Like

Nothing, no errors. Idk how this is not working?

can you send me whole script so i can test in studio?

1 Like

Place_AutoRecovery_0.rbxl (1.9 MB)
Just take the whole file, lol.

well ok lol (most people dont download files so just a advice ; ) )

1 Like

where is the run script? cuz i dont see a similar script to the one above

1 Like

Starter Pack<DRACO<GunScript_Local<Line 2219

1 Like
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

?

Yes, what about it? I have tried your code, and I can still press left-shift and the sprint animation plays.

so here
image
it is “equal to” not a “not equal to” change all the “==” signs to “~=” signs

1 Like

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

yae all on that line

2 Likes

Still unfortunately doesn’t work. Here is my output:

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)