This current script makes it so when you HOLD down the shift key you sprint, however I'd like to make it so when you press the key you can sprint but you don't need to hold the key, and then once you press the key again, you stop sprinting? How would I do this? Your help would be greatly appreciated! :)
wait()local Player=game.Players.LocalPlayer local Mouse = Player:GetMouse() local Speed = 33 local Humanoid = Player.Character:WaitForChild("Humanoid") local OrigSpeed = Humanoid.WalkSpeed
Mouse.KeyDown:connect(function(Key)local Code=Key:byte()if(Code==48)then Humanoid.WalkSpeed = Speed end end) Mouse.KeyUp:connect(function(Key)local Code=Key:byte()if(Code==48)then Humanoid.WalkSpeed = OrigSpeed end end)
I set the button to activate it as shift but you can change that to whatever you want. Don't use KeyDown anymore, it's deprecated, UserInputService is more efficient.
local UserInputService = game:GetService("UserInputService") local Player = game.Players.LocalPlayer Player.CharacterAdded:wait() local Mouse = Player:GetMouse() local Speed = 33 local Humanoid = Player.Character:WaitForChild("Humanoid") local OrigSpeed = Humanoid.WalkSpeed local active = false UserInputService.InputBegan:Connect(function(input) local key = input.KeyCode if key == Enum.KeyCode.LeftShift and active == false then Humanoid.WalkSpeed = Speed active = true elseif key == Enum.KeyCode.LeftShift and active == true then Humanoid.WalkSpeed = OrigSpeed active = false end end)