Improving my Shift to Run system

I have a shift to run system that already works, I was wondering however, if there was a way to get the same result and be neater, fewer lines of code, and maybe if i didn’t catch an issue, for that issue to be resolved. Here is my code:

local UIS = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local RS = game:GetService("RunService")
local char = script.Parent
local humanoid = char.Humanoid
local camera = game.Workspace.CurrentCamera
local shiftKey = Enum.KeyCode.LeftShift
local TI = TweenInfo.new(
	1.5,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)
local Walkspeed = TweenService:Create(humanoid, TI, {WalkSpeed = 14})
local RW = TweenService:Create(humanoid, TI, {WalkSpeed = 8})
local FOV = TweenService:Create(camera, TI, {FieldOfView = camera.FieldOfView + (14 / 8) * (10 + (14 / 8))})
local RFOV = TweenService:Create(camera, TI, {FieldOfView = 45})

local function IsShiftKeyDown()
	return UIS:IsKeyDown(shiftKey)
end

local function Input(input, gameProcessedEvent)
	RS.RenderStepped:Connect(function()
		if IsShiftKeyDown() and humanoid.MoveDirection.Magnitude > 0 then
			Walkspeed:Play()
			FOV:Play()
			task.wait(10)
			RW:Play()
			RFOV:Play()
		else
			RW:Play()
			RFOV:Play()
		end
	end)
end

UIS.InputBegan:Connect(Input)

I mean if you want neater lines of code, I suggest you don’t give your variables 2 letter names because you will later be confused when you come back to the script. These names will especially confuse scripters should you want to hire people to work on your game.

1 Like

try using ContextActionService, it’ll make your code shorter, and you can add mobile buttons! I’ll link a couple documentations for you to read below

resources: ContextActionService, ContextActionService | Roblox Creator Documentation