#Make a sprint script toggle instead of needing to be held down

1 messages · Page 1 of 1 (latest)

short elk
#

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local camera = game.Workspace.CurrentCamera

local UIS = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")

local Configuration = require(game.ReplicatedStorage:WaitForChild("ShiftSprintConfiguration"))

function IsWalking()
if humanoid.MoveDirection.Magnitude > 0 then
return true
else
return false end
end

UIS.InputBegan:Connect(function(key, proccess)
if key.KeyCode == Configuration.RunKey then
if IsWalking() then
humanoid.WalkSpeed = Configuration.RunSpeed
TweenService:Create(camera, TweenInfo.new(Configuration.TweenFovDuration, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {FieldOfView = Configuration.RunFov}):Play()
end
end
end)

UIS.InputEnded:Connect(function(key, proccess)
if key.KeyCode == Configuration.RunKey then
humanoid.WalkSpeed = Configuration.WalkSpeed
TweenService:Create(camera, TweenInfo.new(Configuration.TweenFovDuration, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {FieldOfView = Configuration.WalkFov}):Play()
end
end)

This is the script i use to sprint but i would like to make it toggle and not that i need to hold the shift key to sprint (i have no knowledge about scripting actually learning)