Obby progress bar (Not a straight obby)

My title basically says everything im trying to do.
Im trying to make a progress bar on a obby this is the code right now

the issue is the bar resets when the player gets to the next stage

function Stage:CALC(num, char: Model)
	local primary = char.PrimaryPart
	
	if (primary) then
		local pos_1 = (primary.Position)
		
		local current_pos =  (stageNodes:FindFirstChild(num))
		
		if (current_pos)  then
			local p0  = current_pos.Position
			local p1 = (stageNodes:FindFirstChild(num + 1).Position)
			
			local fullDistance = (p0 - p1).Magnitude
			local difference = fullDistance - (primary.Position - p1).Magnitude
			
			local percentage = math.clamp(difference / fullDistance, 0, 1)
			
			return percentage
		end
	end
	return 1
end

function Stage:Update()
	
	for player, ui in pairs(self.players) do
		
		local character = player.Character
		
		if (character) then
			local leader = player:WaitForChild("leaderstats", 10)
			local stage = leader:WaitForChild("Stage", 10)

			local stage_calc = (stage.Value / 16)
			local difference = self:CALC(stage.Value, character)
			
			local END_CALC = stage_calc * difference
			
			SpringMotion.target(ui, 0.45, 2.5, {
				Position = UDim2.new(END_CALC, 0, 1.083, 0)
			})
		end
	end
end
2 Likes

im not good when it comes to scripting gui but I believe it’s because of the starting node. try moving the starting node to the tween destination

try this

return (percentage + num) / MaxStages --16 for now

Put that instead of

return percentage

Doing that results in the bar basically not moving

can you try printing what percentage on its own prints


image

seems like it prints the value perfectly why are you multiplying it by stage_calc

Thank you, i removed that and it now works!

1 Like

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