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

I can't seem to figure out how to make a script that lets me toggle sprint?

Asked by 5 years ago

I tried making a script where i can toggle on my sprint on and off but it didn't work, is there something that i'm missing?

local player = game.Players.LocalPlayer
local humanoid = player.Character.Humanoid

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftControl then
        humanoid.WalkSpeed = 35
    end
end)


UIS.InputEnded:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftControl then
        humanoid.WalkSpeed = 16
    end
end)

1 answer

Log in to vote
0
Answered by 5 years ago

Your script will change the walkspeed while the key is pressed as you set it back on InputEnded.

You can add in a walk speed check to toggle sprint and remove the InputEnded event.

Example

local player = game.Players.LocalPlayer
local humanoid = player.Character.Humanoid

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftControl then
        if  humanoid.WalkSpeed == 35 then
            humanoid.WalkSpeed = 16
        else
            humanoid.WalkSpeed = 35
        end
    end
end)
0
Thanks! TheOneKingx 7 — 5y
Ad

Answer this question