First of all, I apologize if this is against the rules. I'm really not sure.
I am posting this for anyone who might want it. I learned to code by looking at scripts like this. I hope that this would help new scripters.
I will remove this if asked by an admin.
--[[
-- @author AZDev
-- // A simple sprint script
--]]
local Speed = 16 -- The speed of the player when not running
local MaxSpeed = Speed * 1.5 -- The speed of the player when running (This can be changed to any number)
local SpeedIncreaseIncrement = 0.01 -- This is the speed at which the players speed increases to MaxSpeed
-- Use range from 0.001 to 1 (1 is instant)
local SprintKey = Enum.KeyCode.LeftShift -- Change "LeftShift" to the key you want to use.
---------------------------- Don't change anything below this line ---------------------------------
local Player = game.Players.LocalPlayer
repeat wait() until Player.Character -- If the script executes before the player has loaded it will break
local Character = Player.Character
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Humanoid = Character:WaitForChild("Humanoid") -- Use WaitForChild to prevent errors if the Humanoid isn't loaded
function NumLerp(Start, Finish, Alpha) -- This is to lerp the players speed to max speed
local X = (Start - (Start - Finish) * Alpha)
return X
end
local isRunning = false
Humanoid.WalkSpeed = Speed
function Run()
if not isRunning then
isRunning = true
for i = 0, 1, SpeedIncreaseIncrement do
if not isRunning then break end
RunService.RenderStepped:wait()
Humanoid.WalkSpeed = NumLerp(Humanoid.WalkSpeed, MaxSpeed, i)
workspace.CurrentCamera.FieldOfView = NumLerp(workspace.CurrentCamera.FieldOfView, 80, i)
end
else
isRunning = false
for i = 0, 1, SpeedIncreaseIncrement do
if isRunning then break end
RunService.RenderStepped:wait()
Humanoid.WalkSpeed = NumLerp(Humanoid.WalkSpeed, Speed, i)
workspace.CurrentCamera.FieldOfView = NumLerp(workspace.CurrentCamera.FieldOfView, 70, i)
end
end
end
UserInputService.InputBegan:connect(function(Key)
if isRunning then return end -- No need to run if you already are.
if Key.KeyCode == SprintKey then
Run()
end
end)
UserInputService.InputEnded:connect(function(Key)
if not isRunning then return end -- No need to stop running if your not running
if Key.KeyCode == SprintKey then
Run()
end
end)

1 comment
I think you're gonna want to remove it. It's an interesting script, but they probably want to keep this site dedicated to questions and answers :)