Progress Bar Stuck

Hiya, I’m having some problems with my Progress Bar. I’m confused on how do I input the values in order to achieve a progress bar:

local end_checkpoint_pos = Vector3.new(109.111, 303.919, 5372.981)
local start_checkpoint_pos = Vector3.new(9.495, 62.017, -28.96)

local maxBarLength = (end_checkpoint_pos-start_checkpoint_pos).magnitude

spawn(function()
	while task.wait() do
		
		local distance = (hrp.Position-end_checkpoint_pos).Magnitude
		
		progressbar.DistanceLabel.Text = math.floor(distance).."m"
		
		-- Calculate the progress as a value between 0 and 1
		local progress = math.clamp(maxBarLength/distance, 0, 1)

		-- Update the X scale of the progress bar (size is between 0 and 1)
		progressbar.Bar.Size = UDim2.new(progress, 0, progressbar.Bar.Size.Y.Scale, 0)
		
	end
end)

I have a start_checkpoint_pos which is where the player spawns. It’s a constant, so is the same for end_checkpoint_pos. But the player does try to progress through the map. How would I visualize that?

1 Like

Well it’s some math. So for example if the distance between spawn and the end was 100 studs and we were at 1 stud… that would be 1% completion.

Now we can create a ratio (fraction) to make it easy to show by dividing our position by 100

1/100 or 0.01

And boom now you can tween the green bar part to that value! You can do this for every value like if I was at 2 studs…

2/100 or 0.02


Now you’re probably wondering how we would do that in our code…

Assuming that you built your obby going towards -Z, forward from the origin (0, 0); we can just divide the players’ HumanoidRootPart’s Z position by the end Z position.

local Ratio: Vector3 = HRP.Position.Z / [your_end_pos].Z

And now you can tween by that amount.

Hopefully this works but my math skills aren’t the best

Thank you for your response! This does actually work! But I was also wondering if I could do the same for two vector positions rather than a specific axis. I’ll mark you as solution for now.

1 Like

You probably could but I’m not sure how you’d do that mathematically so I can’t help with that sadly

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.