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

How to make a horizontal distance bar?

Asked by 1 year 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
0
Answered by 1 year 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 = UDim2.new(defaultBarSizeX * distanceRatio, 0, defaultBarSizeY, 0)

Easy as that!

Ad

Answer this question