I am making a slider bar for Mobile users that allow them to change the amount of power they can use based on how far the frame has been dragged.
local absoluteposition = Vector2.new(sliderUI.AbsolutePosition.X, sliderUI.AbsolutePosition.Y)
local absolutesize = Vector2.new(sliderUI.AbsoluteSize.X, sliderUI.AbsoluteSize.Y)
local Multiplier = absolutesize.Y / 15
repeat
local sizeRequirement = (absolutesize.Y + absoluteposition.Y) - mouse.Y
local completeCalculation = math.floor((sizeRequirement + (Multiplier / 2)) / Multiplier) * Multiplier
local powercalculation = math.floor(completeCalculation / 5)
print(powercalculation)
if completeCalculation > 0 and completeCalculation < absolutesize.Y then
slidebar.Size = UDim2.new(1, 0, 0, completeCalculation)
end
task.wait()
until not holdingbar
The issue I am having here is that I am not able to figure out how to calculate the power when the UI is being dragged (The UI works perfectly fine)
Video of the UI: https://gyazo.com/ffe5743cf41f7531e5517f69af21400b
I tried calculating the power by dividing the pixels by 5 and rounding it, but then the result does not give me numbers that are divisible by 5 and sometimes adds 6 from the previous answer.
Example: