Player stops sprinting when camera is moved

Hey guys, today I decided to make a relatively simple movement system for my game, but I’m currently stuck on how to achieve a goal. Whenever the player is running (activated by holding down the left shift key), changing directions or moving the camera causes them to return to their walking speed. I tried tracking the appropriate key binds in my script but that hasn’t yielded any success for me. Below will be the current ModuleScript, any help given trying to overcome this quirk will be appreciated as usual :^D

local runningModule = {}

--Services
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--Values
local canRun = ReplicatedStorage.Values.BoolValues.PlayerMovement.canRun

--Variables
local clientVariables = require(ReplicatedStorage.Modules.Data.clientVariables)
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local running = UserInputService.InputBegan:Connect(function()
	return
end)
local stopping = UserInputService.InputEnded:Connect(function()
	return
end)

local isRunning = false

--Dictionary
local WASDControls = {
	[Enum.KeyCode.W] = false,
	[Enum.KeyCode.A] = false,
	[Enum.KeyCode.S] = false,
	[Enum.KeyCode.D] = false,
	[Enum.KeyCode.Thumbstick1] = false,
}

--Running input
local function run(input)
	return (input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.ButtonA)
end

--Check for WASD controls
local function areWASDControlsReleased()
	return (
		WASDControls[Enum.KeyCode.W] == false
			and WASDControls[Enum.KeyCode.A] == false
			and WASDControls[Enum.KeyCode.S] == false
			and WASDControls[Enum.KeyCode.D] == false
			and WASDControls[Enum.KeyCode.Thumbstick1] == false
	)
end

--Start and stop running
local function startRunning()
	isRunning = true
	humanoid.WalkSpeed = clientVariables.runSpeed
end

local function stopRunning()
	isRunning = false
	humanoid.WalkSpeed = clientVariables.walkSpeed
end

--Enable and disable running, PC/Console
local function enableRunning()
	running = UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
		if isRunning == false and run(input) then
			startRunning()
		end
	end)
	stopping = UserInputService.InputEnded:Connect(function(input, gameProcessedEvent)
		if isRunning == true and areWASDControlsReleased() then
			stopRunning()
		end
	end)
end

local function disableRunning()
	humanoid.WalkSpeed = clientVariables.walkSpeed
	running:Disconnect()
	stopping:Disconnect()
	running = nil
	stopping = nil
end

function runningModule.canPlayerRun()
	if canRun.Value == true then
		enableRunning()
	else
		disableRunning()
	end
end

return runningModule

Hey @magickahat!
From what I see, you’re never actually setting the WASDControls- values?
Try connecting them to a couple of UserInputService.InputBegan- InputEnded- events

Hello, thanks for replying! I’ll try setting them to InputBegan/Ended events in a few minutes, but the reason I didn’t originally was because I wanted to be conservative on how many connections I was setting, for the sake of performance

Ah, well performance is important, but connections don’t tank performance noticeably, until you get to the point where you have them in loops and forget to disconnect them. It’s good to be conservative but only to the point where your systems don’t break because of it

Lmk if it works!

I created more Input events and it appears to be working as I intended now, thanks for pointing out that the values weren’t being set. I had reused some old code from a similar system and just never realized that flaw xD