Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Im confused with a possible way to find the bar placement in a loading bar please help?

I am trying to make an XP bar for a project I am creating but, there is one thing that I can not figure out for the life of me. Its the most important part, I have no idea how to do division or whatever math you need to do to get how far the bar it for example

[-----__] [--------]

I can figure out how to do that, I know how to get a percentage of it, just not how to find out how far it needs to go.

2 answers

✓ Accepted answer

So, the way I would do this is using division, with the slash(/). You’ll have to divide the amount of XP the player has with the total amount of XP needed to level up (Ex: XPplayerhas/XPtolevelup). Then you resize the bar based on that number using UDim2.

Here’s an example script to help you :

local bar = GUI.Bar
local XP = plr.XP
maxXP = 100

XP:GetPropertyChangedSignal(‘Value’):Connect(function()
if XP >= maxXP then
bar.Size = UDim2.new(0, 0, 1, 0)
XP.Value = 0
else
bar.Size = UDim2.new(XP/maxXP, 0, 1, 0)
end)

This script has a function that will run every time the player’s XP in the player changes. The function changes the bar’s size based on the XP and max XP. When it’s over the max XP, it will reset the bar and the player’s XP to 0.

Hope this helped!

2 comments

0

Thanks!

0

I changed it a bit to work with scale instead of offset, I just divided the XP/MaxXP by 1.5, It seems to work well

This is for future uses and anyone who comes on here, Below is what I used for scale

local bar = script.Parent
local XP = 60
maxXP = 100

if XP >= maxXP then
bar.Size = UDim2.new(0, 0, 0.058, 0)
else
local size = XP/maxXP / 1.5
bar:TweenSize(UDim2.new(size, 0, 0.058, 0), 'In', 'Sine', 0.7, true)
end

Not much of a difference besides dividing it to 1.5, and having it Sine

This discussion is preserved as it was. New answers, comments, and votes are closed.