Help with shift to Sprint Script

So, I made a script to sprint script but it doesn’t work

Can someone fix it?

local userInput = game:GetService("UserInputService")
local players = game:GetService("Players")

local sprintSpeed = 30
local walkSpeed = 16

local player = players.LocalPlayer

local function beginSprint(input, Gameprocessed)
    if not Gameprocessed then
        if input.UserInputType == Enum.UserInputType.Keyboard then
            local keycode = input.KeyCode
            if keycode = Enum.KeyCode.LeftShift then
                player.Character.Humanoid.Walkspeed = sprintSpeed
            end
        end
    end
end

local function endSprint(input, Gameprocessed)
    if not Gameprocessed then
        if input.UserInputType == Enum.UserInputType.Keyboard then
            local keycode = input.KeyCode
            if keycode = Enum.KeyCode.LeftShift then
                player.Character.Humanoid.Walkspeed = walkSpeed
            end
        end
    end
end


userInput.InputBegan:Connect(beginSprint)
userInput.InputEnded:Connect(endSprint)
Old script
local userInput = game:GetService("UserInputService")
local players = game:GetService("Players")

local sprintSpeed = 30
local walkSpeed = 16

local player = players.LocalPlayer

local function beginSprint(input, Gameprocessed)
    if not Gameprocessed then
        if input.UserInputType == Enum.UserInputType.Keyboard then
            local keycode = input.KeyCode
            if keycode == Enum.KeyCode.LeftShift then
                player.Character.Humanoid.Walkspeed = sprintSpeed
            end
        end
    end
end

local function endSprint(input, Gameprocessed)
    if not Gameprocessed then
        if input.UserInputType == Enum.UserInputType.Keyboard then
            local keycode = input.KeyCode
            if keycode == Enum.KeyCode.LeftShift then
                player.Character.Humanoid.Walkspeed = walkSpeed
            end
        end
    end
end


userInput.InputBegan:Connect(beginSprint)
userInput.InputEnded:Connect(endSprint)

Try this,

Make sure it is in a local script.

use this script instead.

Where is the script located in your explorer?

I have tested the script and found a typo,

this is the new script it works,

local userInput = game:GetService("UserInputService")
local players = game:GetService("Players")

local sprintSpeed = 30
local walkSpeed = 16

local player = players.LocalPlayer

local function beginSprint(input, Gameprocessed)
    if not Gameprocessed then
        if input.UserInputType == Enum.UserInputType.Keyboard then
            local keycode = input.KeyCode
            if keycode == Enum.KeyCode.LeftShift then
                player.Character.Humanoid.WalkSpeed = sprintSpeed
            end
        end
    end
end

local function endSprint(input, Gameprocessed)
    if not Gameprocessed then
        if input.UserInputType == Enum.UserInputType.Keyboard then
            local keycode = input.KeyCode
            if keycode == Enum.KeyCode.LeftShift then
                player.Character.Humanoid.WalkSpeed = walkSpeed
            end
        end
    end
end


userInput.InputBegan:Connect(beginSprint)
userInput.InputEnded:Connect(endSprint)

1 Like

it is located in starterplayer

it doesnt work, can you tell me the location in case?

I put it in started player script.