Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How To increase Walkspeed when you press shift?

I am trying to make a horror game and i need to know how to increase walkspeed (and other stuff like camera bobbing) when you press shift. btw i already have a first person torso, legs and arms script.

repeat wait() until game.Players.LocalPlayer
local player = script.Parent.Parent
local mouse = player:GetMouse()
mouse.KeyDown:connect(function(key)
    if key == "e" then
--Despacito here 

2 answers

I would actually recommend using userinputservice, yes it is more writing but at least you won't bother by checking all the time which numbers were space, control or in your case shift, also i've heard that it doesn't work anymore and im too lazy to check so there is this one:

wait() --- wait for player to load
local human = script.Parent:FindFirstChild("Humanoid") ---- find humanoid inside player
local UserInputService = game:GetService("UserInputService") --- get userinputservice


 UserInputService.InputBegan:Connect(function(inputObject, gameProcessed) -- use userinputservice in a fuction where the button was pressed
	 if inputObject.KeyCode == Enum.KeyCode.LeftShift then  --- check if button is shift
		human.WalkSpeed = 60 --- change how fast to move
	end
end)

UserInputService.InputEnded:Connect(function(inputObject, gameProcessed)  -- use userinputservice in a fuction where the button was released
	if inputObject.KeyCode == Enum.KeyCode.LeftShift then -- check if button is shift
		human.WalkSpeed = 16 --- change the speed to normal
	end
end)

NOTE: in order for this script to work it must be in StarterPlayer>StarterCharacterScripts or StarterPack also note out that it must be localscript and it must not stay inside of another model/script/tool/etc.

5 comments

0

use if not gameProcessed then ...

0

@yHasteeD ye, that might be an option but i just enjoy making the scripts long, scripting gives me joy so the longer the more fun for me.

0

-1. Too many comments, makes it harder to read. You can improve readability by shortening the comments or moving them outside of the code, or not having them at all.

0

@incapaxian I don't quite get your point, I put all the comments so that people can read them and maybe learn what every part does and maybe learn how to do them alone.

0

richboyfexekapapa ill try the script when i have the time.

You said you wanted to make it increase when you click shift, but this one increses when you click E???

anyways, here.

repeat wait() until game.Players.LocalPlayer
local player = script.Parent.Parent
local mouse = player:GetMouse()
mouse.KeyDown:connect(function(key)
    if key == "e" then
    player.Character.Humanoid.WalkSpeed.Value = 20
--any number works other than 20
end
end)

lol i hope this helped

2 comments

0

bad

0

mouse.KeyDown is deprecated, use UserInputService

This discussion is preserved as it was. New answers, comments, and votes are closed.