Stamina Bar Script

Ok so I’m trying to make a stamina bar script for my game and I found a script that works good. I’ve edited it to my liking, but the stamina bar script only stuck to the specific screen size it was on while I was editing it. I’m trying to fix it, but I’m not that good at scripting to understand it yet. I’ve tried to ask for help from people but no luck yet and I’ve also tried to learn about the funtions but I still don’t really understand it.
The error says “Players.bringtixbackalready.PlayerGui.Stamina.Bar.StaminaClient:50: attempt to perform arithmetic (mul) on number and UDim2” and I know it means that i’m trying to do a math thing with a thing that doesn’t work with it, but I don’t know how to fix it. The people that at least guided me in the right direction said that I had to find the current value of the stamina bar for it to work. How can I do that?
Script:


local Player = game.Players.LocalPlayer
local Character = game.Workspace:WaitForChild(Player.Name)
local UIS = game:GetService("UserInputService")
local Stamina = 20
local IsRunning = false
local staminaValue = Stamina

UIS.InputBegan:Connect(function(input)
 if input.UserInputType == Enum.UserInputType.Keyboard then
  if input.KeyCode == Enum.KeyCode.LeftShift then
   if Stamina >= 1 then
    IsRunning = true
    Character.Humanoid.WalkSpeed = 18
    
    while IsRunning == true do
     if Stamina <= 0 then
      IsRunning = false
	  Character.Humanoid.WalkSpeed = 12
      script.Parent:Destroy()				
     elseif Stamina >= 0 then
	  Stamina = Stamina - 0.25  
     end
     wait(1)
    end
    end
  end
 end
end)

UIS.InputEnded:Connect(function(input)
 if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.LeftShift then
			if Stamina <= 0 then
				IsRunning = false
				Character.Humanoid.WalkSpeed = 12
				script.Parent:Destroy()
			end
   IsRunning = false
   Character.Humanoid.WalkSpeed = 12
   
  end
 end
end)


while true do --Part of script where the error is
	wait(0.1)
	staminaValue = Stamina
	script.Parent:TweenSize((UDim2.new(0, staminaValue * script.Parent.Size)), Enum.EasingDirection.Out, Enum.EasingStyle.Back)
end

I’ve tried to read up on some of the things mentioned in the error, but I’m one of those people who learn better from hands-on stuff and demonstrations that are engaging ;-;

On this line

The part

the size of “script.Parent” gives 2 values, the x and y value of the size, choose one to the script (I don’t know how works your script because I don’t have so much time, so try both to see what’s the correct)

it gonna be something like this

script.Parent:TweenSize((UDim2.new(0, staminaValue * script.Parent.Size.x)), Enum.EasingDirection.Out, Enum.EasingStyle.Back)

or this

script.Parent:TweenSize((UDim2.new(0, staminaValue * script.Parent.Size.y)), Enum.EasingDirection.Out, Enum.EasingStyle.Back)

Thanks for the help, first one wielded this error: “x is not a valid member of UDim2”
I’ll try the other one now
Edit: second one didn’t work aswell and said “y is not a valid member of UDim2”

Are you making the stamina thing where if you run the bar goes down, theres a another way to do this

Yes, the bar is supposed to go down but I want it to have a bobbing animation for a lil’ flare

You can try this

tween:create(YourChildFrame, tweeninfostuff, {Size = UDim2.new(0, 0, currentstamina / maxstamina, 0)}):Play()

Yourchildframe must be the frame within the bar that fills the bar
tweeninfostuff is just the tween info, make it and thats it

That’s the thing, I don’t know how to get the current value of the stamina

Make 2 different values, one is currentstamina and one is maxstamina,
imagine this

maxstamina = 20
currentstamina = maxstamina

--then do this when aperson is sprinting
currentstamina -= 1

Sorry, i’m not that good at tweens yet but this is the error it gave me: “Players.bringtixbackalready.PlayerGui.Stamina.Bar.StaminaClient:49: attempt to call missing method ‘create’ of table”
Here is what I put:

while true do
	wait(0.1)
	CurrentStamina -= 1
	TweenInfo:create(script.Parent, Enum.EasingStyle.Back, {Size = UDim2.new(0, 0, CurrentStamina / Stamina, 0)}):Play()
end

Its not TweenInfo its TweenService, Make a variable called local TweenService = game:GetService("TweenService")

Sorry for the late reply, I had to go to bed ;-; I’ll see what I can do. Thanks for the help