Progress UI issue

This is what I have tried

local Bar = script.Parent.Background.Bar

local plr = game.Players.LocalPlayer

local Char = plr.Character

local HRP = Char:WaitForChild("HumanoidRootPart")

local ProgressDisplay = script.Parent.Background.Progress

local TopHeight = 300

repeat task.wait() until HRP

while true do
	
	if HRP.Position.Y <= TopHeight then
		
		ProgressDisplay.Text = "Progress: " .. math.floor(HRP.Position.Y / TopHeight * 100) .. "%"

		Bar:TweenSize(UDim2.new(HRP.Position.Y / TopHeight,0,1,0),Enum.EasingDirection.In,Enum.EasingStyle.Sine,0.1)

		Bar.BackgroundColor3 = Color3.fromRGB(200,0,0):Lerp(Color3.fromRGB(85, 255, 127),HRP.Position.Y / TopHeight)

		task.wait()
		
	end
	
end

The issue is that when i get to the topheight it doesnt scale correctly

It sounds like your progress bar isn’t scaling correctly once your character reaches the specified height. One way to approach this issue is to manually set a maximum value for the progress bar’s size, and then adjust the size proportionally as the player’s character moves up.

local Bar = script.Parent.Background.Bar
local plr = game.Players.LocalPlayer
local Char = plr.Character
local HRP = Char:WaitForChild("HumanoidRootPart")
local ProgressDisplay = script.Parent.Background.Progress
local TopHeight = 300
local MaxBarWidth = 150 


Bar.Size = UDim2.new(0, 0, 1, 0)

repeat task.wait() until HRP

while true do
    if HRP.Position.Y <= TopHeight then
        local progress = HRP.Position.Y / TopHeight -- calculate progress as a decimal between 0 and 1
        ProgressDisplay.Text = "Progress: " .. math.floor(progress * 100) .. "%" 
        local newWidth = MaxBarWidth * 
        Bar:TweenSize(UDim2.new(0, newWidth, 1, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.1) 
        Bar.BackgroundColor3 = Color3.fromRGB(200,0,0):Lerp(Color3.fromRGB(85, 255, 127), progress) 
    end
    task |