When the player drags the bar, the value that is returned from the module script ranges from -0.5 to 0.5.
The problem is, only a small section of the bar seems to be actually changing value, with a section of the lower and upper half of the bar returning 1.5.
The max and min values should only be returned when the player drags the bar completely full or completely empty, I think(?) I’m doing something wrong with my math.clamp in the local script, but I’m not sure.
https://gyazo.com/e5cf69a7d4169df97b604714dcee8dd4
Local Script
local function dragSlider(_, _, input)
local BarSlider = SliderManager.new(HeightBar:FindFirstChildWhichIsA("Frame")) -- Construct slider class
local size = BarSlider:DragBar(input.Position) -- passing in the mouse location
HeightValue = math.clamp(HeightValue+size, 0.5, 1.5) -- Clamp the player height to between 0.5 and 1.5
print(HeightValue)
end
Module Script
function SliderManager:DragBar() -- Drags slider and returns slider value(s)
-- Dragging bar visual effect
local absolutePos = Vector2.new(self.BarButton.AbsolutePosition.X, self.BarButton.AbsolutePosition.Y)
local mouseLoc = UserInputService:GetMouseLocation()
local max = self.BarButton.AbsoluteSize.X
self.Bar.Size = UDim2.new(0, math.clamp(mouseLoc.X - absolutePos.X, 0, max), 1, 0) -- bar size changes position to mouse x position
-- Calculate bar value out of 100
local MaxSize = Vector2.new(self.BarButton.AbsoluteSize.X, self.BarButton.AbsoluteSize.Y)
local size = self.Bar.AbsoluteSize
-- "+0.5" , any value above 0.5 rounds up
-- 100 is the total range of values, while -50 is the min value
local value = math.floor((100 * (size.X / MaxSize.X) + 0.5)-50)
return value/100
end