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

How do I do key presses like if someone presses the shift key they sprint?

I know how to make a character go faster i just need to figure out how to do keypresses and all that help please

2 answers

Well, to detect when you press a key, you need use a function called KeyCode, you can see this article for more information : https://wiki.roblox.com/index.php?title=API:Enum/KeyCode

I use this type of KeyCode in my scripts :

if key.KeyCode == Enum.KeyCode.Z then

end

you can change the "Z" for the key that you want, and this function need be in a LocalScript

8 comments

0

oh, i usually put the script in GUIs, but i think that this can work with StarterPlayersScripts too, Backpack and etc.

0

i think you can also you key byte codes but i dont know if thats deprecated or not

0

It is deprecated

0

How would i do this for shift do i just change Z to Shift?

0

yes

0

Please, if this answer is good to you, mark as accepted, thanks ^^ (you need use LeftShift or RightShift instead of Z)

0

Ok how would i make it stop sprinting when they release LeftShift?

0

uif = game:GetService("UserInputService") / use this = uif.InputEnded:connect(function(imput)

Hello Tacodragon777, you can use the Service called "UserInputService" to deal with keys heres an example below

 local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then-- you can change the letter "E" to any other Key
--then put what happens down here like
print("It works!")

2 comments

0

maybe belew the then, you can put game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = game.Players.LocalPlayer.Character.Humanoid.WalkSpeed + 20

0

And By the Way.This IS a Local Script.

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