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

Trying to change walkspeed when shift is pressed?

Asked by 8 years ago

Basically a sprint system. No output errors just nothing happens, anyone know whats wrong? Any help is appreciated and here's the code:

player = script.Parent.Parent
character = player.Character
local sprinting = false

function onKeyPress(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then
        if sprinting == false then
            sprinting = true
            character.Humanoid.WalkSpeed = 24
            wait(8)
            character.Humanoid.WalkSpeed = 16
        else
            character.Humanoid.WalkSpeed = 16
        end
    end
end

game.ContextActionService:BindAction("keyPress", onKeyPress, false, string.char(48))

Edit: It's in StarterPlayerScripts

1 answer

Log in to vote
2
Answered by
0_0 70
8 years ago
player = game.Players.LocalPlayer
character = player.Character
local sprinting = false

function onKeyPress(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then
    print("test")
        if sprinting == false then
            sprinting = true
            character.Humanoid.WalkSpeed = 24
            wait(8)
        sprinting = false
            character.Humanoid.WalkSpeed = 16
        else
            character.Humanoid.WalkSpeed = 16
        end
    end
end

game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.LeftShift)

Change

string.byte(48) to Enum.KeyCode.LeftShift

Confirmed working.

http://wiki.roblox.com/?title=API:Enum/KeyCode

All the best.

Ad

Answer this question