Health/Stamina Bar Scaling Issue

Hello, I have a problem with the stamina scaling and health bar that are displayed in the video below. I need the bar to drain from top to bottom because it currently drains from the right to left side. Although I tried to adjust the AnchorPoint, I wasn’t able to find a solution. Would someone kindly assist?

Script here:


local Player = game.Players.LocalPlayer

while not Player.Character do wait() end

local Character = Player.Character

local Humanoid = Character:WaitForChild("Humanoid")

local Healthbar = script.Parent.Health.Bar

local Redbar = script.Parent.Health.Red

local Stambar = script.Parent.Stamina.Bar

local maxhealth = 100

local maxstamina = 100

local TweenService = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(

.2,

Enum.EasingStyle.Linear,

Enum.EasingDirection.Out

)

Player.Character.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()

local newTween = TweenService:Create(Healthbar,tweenInfo,{Size = UDim2.new(Humanoid.Health/maxhealth,0,1,0)})

newTween:Play()

wait(.2)

local newTween2 = TweenService:Create(Redbar,tweenInfo,{Size = UDim2.new(Humanoid.Health/maxhealth,0,1,0)})

newTween2:Play()

end)

Player:WaitForChild("States"):WaitForChild("Stamina").Changed:Connect(function()

local newTween = TweenService:Create(Stambar,tweenInfo,{Size = UDim2.new(Player.States.Stamina.Value/maxstamina,0,1,0)})

newTween:Play()

end)

A few things:

That can be reduced to
local Character = Player.Character or Player.CharacterAdded:Wait()

This is why it’s scales from right to left, you are still scaling on the x axis (anchor point won’t change that)

To fix this, change that to
local newTween = TweenService:Create(1,0 Stambar,tweenInfo,{Size = UDim2.new(Player.States.Stamina.Value/maxstamina,0)})

BTW, make sure you do the same for:

and

Change

Size = UDim2.new(Player.States.Stamina.Value/maxstamina,0,1,0

to

Size = UDim2.new(1,0,Player.States.Stamina.Value/maxstamina,0

You were scaling the wrong axis

2 Likes

Was almost a fix… the code you gave does this:

image

local newTween = TweenService:Create(Stambar,tweenInfo,{Size = UDim2.new(0,1,Player.States.Stamina.Value/maxstamina,0)})

Ok, what is your anchor point? Try setting the anchor point to (0,1) and placing the bar as should.

It was (0.5,0.5) before. When changed to (0,1) it’s now blank.

image

The AnchorPoints currently:
Screen Shot 2022-06-23 at 3.56.30 PM

What’s the position? Make the bar size 1,0 and place the bar correctly, then set the size back down to what it was

i do this by moving the bar as its size is reduced, because it gets closer to the top left as it shrinks.

Position = UDim2.new(0,0,1,0) --Places bar at bottom
.Size = UDim2.new(1,0,0,0) --Makes bar flat

TweenService:Create(Instance,Info,{ Size = UDim2.new(1,0,Y,0), Position = UDim2.new(0,0,1-Y,0) }

it’s something like that, i really only make the bar go from 0 to 1, not to any point between like in your case

Thank you so much!

Remember to mark their reply as the thread’s solution.