Scripting Helpers is winding down operations and is now read-only. More info→
Log in to vote

How to make a horizontal distance bar?

Asked by 2 months ago

so i just have like a glass bridge game and want to show how far the players are with a bar

1 answer

Log in to vote
Answered by 2 months ago

Alright, here's how I would do it.

Find the distance of the player to the distance of the player to the starting point and divide it by the distance of the starting point to the ending point.

-- this code assumes the starting point, ending point, and player are all defined
local playerDistanceCovered = (player.Character.HumanoidRootPart.Position - startingPoint.Position).magnitude
local totalDistance = (endingPoint.Position-startingPoint.Position).magnitude
local distanceRatio = math.clamp(playerDistanceCovered/totalDistance, 0, 1)

Now that you have the distance ratio, you just need to change a GUI's size.

-- this code assumes you have your distance bar and the default size of your bar defined
distanceBar.Size = * distanceRatio, 0, defaultBarSizeY, 0)

Easy as that!


Answer this question