Recently roblox released a new beta feature - UIDragDetector. This feature motivated me to make template for my further projects, but i’ve ran into a problem
I tried to make this bar for my settings ui,
but i couldn’t find an accurate way to calculate percentage.
Right now im stuck with extremely inaccurate (only 91% at full bar) solution for it.
The code:
--Variables
local greenbar = script.Parent
local ui = greenbar.Parent
local redbar = ui.RedBar
local draggableframe = ui.DraggableObject
-- Functions
local function updatebar()
local size = draggableframe.Size.X.Scale
local percentage = (greenbar.AbsoluteSize.X - draggableframe.AbsoluteSize.X) / (redbar.AbsoluteSize.X)
print(math.ceil(percentage*100))
local barsize = (draggableframe.Position.X.Scale - redbar.Position.X.Scale) + draggableframe.Size.X.Scale
print(barsize)
greenbar.Size = UDim2.new(barsize, 0, greenbar.Size.Y.Scale, 0)
end
-- Connections
draggableframe:GetPropertyChangedSignal("Position"):Connect(updatebar)