Making A Sprint Buildup System!

Hello there! This tutorial will help you create a system that lets you run faster over time.

Let’s get into it!


Step 1

Create a new LocalScript in game.StarterPlayer.StarterPlayerScripts. We want the script to be a part of the player, not the character.

Step 2

Let’s add our Services.

--// Services
local UIS = game:GetService("UserInputService") -- To detect when the Shift button are pressed *& released
local TS = game:GetService("TweenService") -- To create a buildup effect for our WalkSpeed
local plr = game.Players.LocalPlayer

Step 3

Now onto the InputBegan and InputEnded listeners.

--// Services
local UIS = game:GetService("UserInputService") -- To detect when the Shift button are pressed *& released
local TS = game:GetService("TweenService") -- To create a buildup effect for our WalkSpeed
local plr = game.Players.LocalPlayer

--// Listeners
UIS.InputBegan:Connect(function(key) -- 'key' is the Object 'key' pressed
	
end)

UIS.InputEnded:Connect(function(key) -- 'key' is the Object 'key' let go of
	
end)

We want to make sure its only a specific key or keys that are pressed/let go of to trigger the sprint. In this case, it’ll be LeftShift and RightShift.

--// Services
local UIS = game:GetService("UserInputService") -- To detect when the Shift button are pressed *& released
local TS = game:GetService("TweenService") -- To create a buildup effect for our WalkSpeed
local plr = game.Players.LocalPlayer

--// Listeners
UIS.InputBegan:Connect(function(key) -- 'key' is the Object 'key' pressed
	if key.KeyCode == Enum.KeyCode.LeftShift or key.KeyCode == Enum.KeyCode.RightShift then
		
	end
end)

UIS.InputEnded:Connect(function(key) -- 'key' is the Object 'key' let go of
	if key.KeyCode == Enum.KeyCode.LeftShift or key.KeyCode == Enum.KeyCode.RightShift then
    	
	end
end)

We’re not done! We want to actually make our system change the WalkSpeed. To do so, we will need to create a new TweenService object and play it.

--// Services
local UIS = game:GetService("UserInputService") -- To detect when the Shift button are pressed *& released
local TS = game:GetService("TweenService") -- To create a buildup effect for our WalkSpeed
local plr = game.Players.LocalPlayer

--// Listeners
UIS.InputBegan:Connect(function(key) -- 'key' is the Object 'key' pressed
	if key.KeyCode == Enum.KeyCode.LeftShift or key.KeyCode == Enum.KeyCode.RightShift then
		TS:Create(plr.Character.Humanoid, TweenInfo.new(2), {WalkSpeed = 32}):Play()
		-- '2' is the time it takes to reach maximum speed
		-- '32' is the maximum speed
	end
end)

UIS.InputEnded:Connect(function(key) -- 'key' is the Object 'key' let go of
	if key.KeyCode == Enum.KeyCode.LeftShift or key.KeyCode == Enum.KeyCode.RightShift then
    	TS:Create(plr.Character.Humanoid, TweenInfo.new(2), {WalkSpeed = 16}):Play()
		-- '2' is the time it takes to reach normal speed
		-- '16' is the normal WalkSpeed of a player
	end
end)

Thanks for reading! If you create a variation of this system, consider posting it here for others to benefit and learn from.

21 Likes

Not sure if I missed something, but you forgot to define plr. Edit: This is now fixed in their edit

2 Likes

PROBLEM
when standing while holding the run key the player can build up speed without moving.

FIX
add a check using Humanoid.MoveDirection making sure the player is moving.

1 Like