Stamina bar script not working

I’m trying to make a script that detects when the player is running by holding LeftShift, and if they are, deplete a stamina bar GUI that I’ve made.

Here’s the script:

local player = game.Players.LocalPlayer
local char = player.Character

local UIS = game :GetService(“UserInputService”)

local stamina = 250
local isRunning = false

stamina = math.clamp(stamina, 0, 250)

UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
isRunning =true
char.Humanoid.Walkspeed = 28

	while stamina > 0 and isRunning do
		stamina = stamina -1
		script.Parent:TweenSize(UDim2.new(stamina/250, 0, 1,0 ), "Out", "Linear", 0)
		wait()
		if stamina <= 0 then 
			char.Humanoid.Walkspeed = 16
		end
	end
end

end)

UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
isRunning = false
char.Humanoid.Walkspeed = 16

	while stamina <250 and not isRunning do
		
		stamina = stamina +0.5
		
		script.Parent:TweenSize(UDim2.new(stamina/250, 0, 1 , 0), "Out", "Linear",0)
		wait()
		if stamina == 0 then
			char.Humanoid.Walkspeed = 16
		end
	end
end

end)

I’ve put this script into a LocalScript which is placed in the stamina bar GUI. But when I go in game to test, I can’t run, and the stamina bar does not deplete. However, I am using a skinned mesh character (the roblox default skinned mesh rig), not sure if that makes a difference.

Any help is appreciated. Also, I am not a scripter. I know very little.