Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago

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

0
oh, i usually put the script in GUIs, but i think that this can work with StarterPlayersScripts too, Backpack and etc. darkzerobits 92 — 6y
0
i think you can also you key byte codes but i dont know if thats deprecated or not Wad_dles 15 — 6y
0
It is deprecated User#19524 175 — 6y
0
How would i do this for shift do i just change Z to Shift? Tacodragon777 -1 — 6y
View all comments (4 more)
0
yes darkzerobits 92 — 6y
0
Please, if this answer is good to you, mark as accepted, thanks ^^ (you need use LeftShift or RightShift instead of Z) darkzerobits 92 — 6y
0
Ok how would i make it stop sprinting when they release LeftShift? Tacodragon777 -1 — 6y
0
uif = game:GetService("UserInputService") / use this = uif.InputEnded:connect(function(imput) darkzerobits 92 — 6y
Ad
Log in to vote
0
Answered by
Tizzel40 243 Moderation Voter
6 years ago

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!")
0
maybe belew the then, you can put game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = game.Players.LocalPlayer.Character.Humanoid.WalkSpeed + 20 Tizzel40 243 — 6y
0
And By the Way.This IS a Local Script. Tizzel40 243 — 6y

Answer this question