I'm trying to make a sprint script for my game and a player could just run and tap shift then have the speed forever. If they press anything else but w (example: a or d) it cancels. Note forever means they don't have to press shift.

Here is an example script:

local UserInputService = game:GetService("UserInputService")
 local character = game.Players.LocalPlayer.Character
-- Shift keys
local shiftKeyL = Enum.KeyCode.LeftShift

 
-- Return whether left or right shift keys are down
local function IsShiftKeyDown()
	return UserInputService:IsKeyDown(shiftKeyL) 
end
 
-- Handle user input began differently depending on whether a shift key is pressed
local function Input(input, gameProcessedEvent)
	if not IsShiftKeyDown() then
		character.Humanoid.WalkSpeed = 16
	else
		character.Humanoid.WalkSpeed = 25
	end
end
 
UserInputService.InputBegan:Connect(Input)

1 comment

0

try using events