How do i make a script so when a player presses a key (R) they run faster?
✓ ANSWER ACCEPTED
Press key then run script?
3 answers
✓ Accepted answer
Place this code in a LocalScript. Holding 'r' will cause the player to run faster. Releasing 'r' returns the player to the original walk speed.
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character.Humanoid
local mouse = player:GetMouse()
local origSpeed = humanoid.WalkSpeed
local runSpeed = 100 --modify this value to be the speed you want when running
mouse.KeyDown:connect(function(key)
if key:lower() == "r" then
humanoid.WalkSpeed = runSpeed
end
end)
mouse.KeyUp:connect(function(key)
if key:lower() == "r" then
humanoid.WalkSpeed = origSpeed
end
end)
1 comment
0
can you make it so when we press r once it will run? and when we press it again
You're going to use the .KeyDown() function.
You're going to have to get the players mouse.
1 comment
0
I know that....
If you want the script, then look here.
NOTE: Added some tags for your understanding.
repeat wait() until game.Players.LocalPlayer--Also, this is local script because this is being used by the player
local p = game.Players.LocalPlayer--P is for players
local m = p:GetMouse()--m is for mouse
m.KeyDown:connect(function(key)
I key: lower() == "R" then--R is for run
Sorry not full answer, I forgot what to do XD
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
here is the script for holding R to change your walkspeed (if you want a different keybind, explained in script)