Issue with Sprinting

I’m trying to make a sprinting mechanic, where when you hold left shift, your character runs faster. I tried doing this with a while loop and printing if they were sprinting, but it didn’t work… Please help.

local Script:

local UIS = game:GetService("UserInputService")
local RP = game:GetService("ReplicatedStorage")
local Event = RP:WaitForChild("SprintingEvent")

local Sprinting = false

UIS.InputBegan:Connect(function(input, typing)
	if typing then return end
	while Sprinting == true do
		wait()
		if input.KeyCode == Enum.KeyCode.LeftShift then
			print("Sprinting!")
			Event:FireServer()
		end
	end
end)

Server:

local RP = game:GetService("ReplicatedStorage")
local Event = RP:WaitForChild("SprintingEvent")

Event.OnServerEvent:Connect(function(player)
	print("Sprinting!")
end)

Use UserInputService.InputEnded instead of a while loop.

Example:

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input, typing)
	if typing then return end
        
    if input.KeyCode == Enum.KeyCode.LeftShift then
        print("Sprinting!")
    end 
end)

UIS.InputEnded:Connect(function(input, typing)
	if typing then return end
        
    if input.KeyCode == Enum.KeyCode.LeftShift then
        print("Stopped Sprinting!")
    end 
end)

Also make sure to change the Player’s WalkSpeed whenever they do hold the sprint button in the Server Script

Event.OnServerEvent:Connect(function(player)
    player.Character.Humanoid.WalkSpeed = 32
	print("Sprinting!")
end)

(Maybe you could do this locally as well idk)