Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Trying to change walkspeed when shift is pressed?

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

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.