I need help making a hold shift to run script, anyone know how to?
✓ ANSWER ACCEPTED
Does anyone know how to make a hold shift to run script? and when u stop holding down sprint stops?
2 answers
✓ Accepted answer
Attention to any mods, if I'm breaking any rules please let me know - I will take my answer down.
So, I'm going to use many comments to explain what's happening so this person can learn.
Read this script - the comments too, hope this helps..
print("Sprint Script Loaded")
-- You must put this in a local script because it's handling user input
-- This script should go in StarterPlayer > StarterCharacterScripts
-- We can only access LocalPlayer in a LocalScript it cannot be accessed in a server script nor ModuleScript
player = game.Players.LocalPlayer
mouse = player:GetMouse() -- This is what will be detecting if you pressed a key
-- Here we create a function with a parameter 'key' key is the key that was pressed
local function onKeyDown(key)
-- This checks to see if the key code is the same as shift
if string.byte(key) == 48 then -- 48 is the keycode to shift
player.Character.Humanoid.WalkSpeed = 29 -- This is changing the persons walkspeed
end
end
local function onKeyUp(key) -- a function going to be fired when a key is released
if string.byte(key) == 48 then -- Again here we check to see if it's the shift key
player.Character.Humanoid.WalkSpeed = 16 -- Here we are changing the walkspeed back to default which is 16
end
end
-- Here we are connecting the two functions to the 'KeyDown' and 'KeyUp' events.
mouse.KeyDown:connect(onKeyDown)
mouse.KeyUp:connect(onKeyUp)
not a specific question about scripting, that's more of a "give me stuff i need which i wont make the effort to think a lot about" however, you could start by:
local plr = ...
local mouse = plr:GetMouse()
mouse.KeyDown:connect(function(key)
if key == "r" then
....
end
end)
mouse.KeyUp:connect(function(key)
if key == "r" then
...
end
end)
Idk how to refer to shift
1 comment
0
Kiriyato, Actually you can refer to shift using the key code 48 like this - string.byte(key) and use an if statement to see if it is that same key code.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
http://wiki.roblox.com/index.php?title=UserInputService
http://wiki.roblox.com/index.php?title=API:Enum/KeyCode