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

[Newbie] - Sprinting (Shift on, Shift off)?

I found this script from the catalog:

repeat wait() until game.Players.LocalPlayer

Run = game.Players.LocalPlayer:GetMouse()

Run.KeyDown:connect(function(key) if key == "0" then print("Running Now") game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 40 end end)

Run.KeyUp:connect(function(key) if key == "0" then game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16 end end)

**I want to be able to toggle shift on(lock it)press only once(running) and shift second time to activate off (walking)

**

2 comments

0

Scripting Helpers is here to help resolve issues with scripts you wrote, not ones you find in the catalog.

0

sry

1 answer

Well that script you found is using the Mouse.KeyDown event, that is deprecated. Do not use it. Use the ContextActionService or UserInputService to do this.

function run()
    local plr = game:GetService("Players").LocalPlayer
    local char = plr.Character

    if not char then
        char = plr.CharacterAdded:Wait()
    end

    local hum = char:WaitForChild"Humanoid"

    if hum.WalkSpeed == 40 then
        hum.WalkSpeed = 16
    elseif hum.WalkSpeed ~= 16 and hum.WalkSpeed < 40 then -- anything can make a humanoid faster/slower
        hum.WalkSpeed = 40
    end
end

game:GetService("ContextActionService"):BindAction("Run",
run,
false,
Enum.KeyCode.LeftShift
)

1 comment

0

ty i am learning

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