Help with shift to sprint script

i’m trying to make a shift to sprint script which you dont need to hold down shift and if you press shift again it turns off the shift to sprint, I’m struggling hard please help.

1 Like

Use InputBegan and InputEnded.

Here’s an example, or just use this:

local InputService = game["UserInputService"]--Input Service
local TweenService = game["TweenService"]--Tween Service
local TI = TweenInfo.new(1)-- Tween Information(You can change this to your liking)
local Player = game.Players.LocalPlayer--The Player

InputService.InputBegan:Connect(function(input, processedEvent)--When shift is pressed
	if processedEvent then return end --if the player is interacting with roblox menu, for example: shiftlocking, then dont do anything.
	
	if not processedEvent and input.KeyCode == Enum.KeyCode.LeftShift then --if pressing shift and not doing processed event then
		Player.Character.Humanoid.WalkSpeed = 30 --Increase walkspeed
		TweenService:Create(workspace.CurrentCamera,TI,{FieldOfView = 90}):Play()--Tween FOV(Delete this if you Dont want FOV Tween)
	end
end)

InputService.InputEnded:Connect(function(input, processedEvent)--when shift is let go
	if processedEvent then return end--check if player isnt interacting with roblox menu

	if not processedEvent and input.KeyCode == Enum.KeyCode.LeftShift then --if not interacting and is pressing shift then
		Player.Character.Humanoid.WalkSpeed = 16--change walkspeed back
		TweenService:Create(workspace.CurrentCamera,TI,{FieldOfView = 70}):Play()--change FOV back(You can delete this if you dont want to change FOV)
	end
end)

Put this in StarterPlayer, StarterCharacterScripts, and enjoy!

1 Like

Just add a boolean in your script that listens for the player input, while the boolean is true, player has higher walkspeed, until boolean is false (aka. player has clicked left shift again)

how do i do this with animations?

Im not experienced with animations, but here’s what can work.

local InputService = game["UserInputService"]--Input Service
local TweenService = game["TweenService"]--Tween Service
local TI = TweenInfo.new(1)-- Tween Information(You can change this to your liking)
local Player = game.Players.LocalPlayer--The Player

local Animator = Player.Character.Humanoid.Animator--Roblox Animator
local RunAnimation = Instance.new("Animation")--New Animation

RunAnimation.AnimationId = "rbxassetid://"--Your Animation ID
if Animator:LoadAnimation(RunAnimation) then--Check if its loaded or if it exists
	print("Animation Loaded")
end

RunAnimation.Parent = Player.Character.Humanoid--Set the Animation Parent to the players Humanoid

InputService.InputBegan:Connect(function(input, processedEvent)--When shift is pressed
	if processedEvent then return end --if the player is interacting with roblox menu, for example: shiftlocking, then dont do anything.
	
	if not processedEvent and input.KeyCode == Enum.KeyCode.LeftShift then --if pressing shift and not doing processed event then
		Player.Character.Humanoid.WalkSpeed = 30 --Increase walkspeed
		TweenService:Create(workspace.CurrentCamera,TI,{FieldOfView = 90}):Play()--Tween FOV(Delete this if you Dont want FOV Tween)
		Animator:LoadAnimation(RunAnimation):Play()--Play Animation
	end
end)

InputService.InputEnded:Connect(function(input, processedEvent)--when shift is let go
	if processedEvent then return end--check if player isnt interacting with roblox menu

	if not processedEvent and input.KeyCode == Enum.KeyCode.LeftShift then --if not interacting and is pressing shift then
		Player.Character.Humanoid.WalkSpeed = 16--change walkspeed back
		TweenService:Create(workspace.CurrentCamera,TI,{FieldOfView = 70}):Play()--change FOV back(You can delete this if you dont want to change FOV)
		Animator:LoadAnimation(RunAnimation):Stop()--Stop Animation
	end
end)

Or get the Animate Script from the players character when testing the game and paste it in starterPlayer and change the Running animation ID.

it doesn’t work
there are no errors though

There could be 3 problems:
1.The animation is not yours
2.The animation is playing over the Roblox one
3.You kept the animation ID field blank.

Try getting the Animate script from the character and pasting it in starter player and changing the run animation ID.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.