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

Does anyone know how to make a hold shift to run script? and when u stop holding down sprint stops? [closed]

Asked by 6 years ago

I need help making a hold shift to run script, anyone know how to?

Closed as Not Constructive by theCJarmy7, TheeDeathCaster, xAtom_ik, and InfinitivePixelsJr

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

2 answers

Log in to vote
0
Answered by 6 years ago

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)
Ad
Log in to vote
0
Answered by 6 years ago

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

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. andyad13 74 — 6y