I'm a little bit of a noob to UserInputService. I don't think I've ever used anything other than the player's mouse. Anyways, I'm trying to make the player able to sprint. This script goes like this, placed in a local script inside StarterPlayerScripts:
local player = game.Players.LocalPlayer
local char = player.Character
local hum = char:WaitForChild("Humanoid")
local defaultws = hum.WalkSpeed
local uis = game:GetService("UserInputService")
function onKeyPress(input)
if input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.RightShift then
hum.WalkSpeed = 20
end
end
function onKeyLeave(input)
if input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.RightShift then
hum.WalkSpeed = defaultws
end
end
uis.InputBegan:connect(onKeyPress)
uis.InputEnded:connect(onKeyLeave)
Any help is appreciated. Thanks! ~Loughdough

1 comment
Are there any errors? What happens that isn't meant to happen?