DEV Community

Cover image for Scripts: Super speed
Matthew Ramirez
Matthew Ramirez

Posted on

Scripts: Super speed

Hi! This is my first post, and today I learned how to create a Super Speed script. The character will be able to increase their speed when the player holds down the Shift key.

Where should we place our script?

It should be placed close to the Character — inside StarterPlayer -> StarterCharacterScripts. This way, our script will have context about the Character’s children, such as the Humanoid.

We’ll use UserInputService to handle user inputs and update the Humanoid’s WalkSpeed.

local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local defaultWaklSpeed = humanoid.WalkSpeed

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(
    function(input, processed)
        if not processed and input.KeyCode == Enum.KeyCode.LeftShift then
            print("Se esta presionando shift")

            humanoid.WalkSpeed = defaultWaklSpeed * 2
        end
    end
)

UserInputService.InputEnded:Connect(
    function(input)
        if input.KeyCode == Enum.KeyCode.LeftShift then
            print("Se dejo de presionar shift")

            humanoid.WalkSpeed = defaultWaklSpeed
        end
    end
)
Enter fullscreen mode Exit fullscreen mode

Thanks for reading, have fun!

Top comments (0)