I am making a stamina bar for my game but I keep getting an Attempt to call Udim2 value error whenever I press LeftShift, I get the error. What is happening, could anyone please help? Here is the code:
local player = game.Players.LocalPlayer
local charcter = player.Character
local UserInputService = game:GetService("UserInputService")
local Stamina = 100
local running = false
Stamina = math.clamp(Stamina, 0, 100)
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
running = true
charcter.Humanoid.WalkSpeed = 22
while Stamina > 0 and running do
Stamina = Stamina-0.6
script.Parent:TweenSize(UDim2.new(Stamina/ 100, 0, 1, 0) "Out", "Linear", 0)
wait()
if Stamina == 0 then
charcter.Humainoid.WalkSpeed = 16
end
end
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
running = false
charcter.Humanoid.WalkSpeed = 16
while Stamina < 100 and not running do
Stamina = Stamina+0.5
script.Parent:TweenSize(UDim2.new(Stamina/ 100, 0, 1, 0) "Out", "Linear", 0)
wait()
if Stamina == 0 then
charcter.Humainoid.WalkSpeed = 16
end
end
end
end)