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

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

Asked by 6 years ago

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)

**

0
Scripting Helpers is here to help resolve issues with scripts you wrote, not ones you find in the catalog. lukeb50 631 — 6y
0
sry NewbieScripting 0 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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
)
0
ty i am learning NewbieScripting 0 — 6y
Ad

Answer this question