Players.larryboydev.PlayerScripts.Sprint:10: attempt to index nil with 'UserInputType'

Im making a sprint script where you click the left shift you sprint. I ran into this error and I need help solving it. Thank you for taking your time to help me.

here is the code:

local userInput = game:GetService('UserInputService')
local player = game.Players.LocalPlayer

local sprintSpeed = 30
local walkSpeed = 16


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())
--

\

You accidently called the functions in :Connect() instead of passing them.

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

You called the functions instead of connecting it inside the :Connect()

Thank you for your help. Iā€™m blind.