I’m trying to replicate the Osu main menu. I successfully made the bop but the ImageButton (the one I’m using to resize) gets too small I wanted the minimum size to be the ImageButton’s default size which is 0.25,0,0.25,0 with the SizeContraint with RelativeXX.
Here is my script:
local music = script.Parent.Audio.Sound
local button = script.Parent
local TweenService = game:GetService("TweenService")
local maxLoudness = 1300
while true do
local amplitude = math.clamp(music.PlaybackLoudness / maxLoudness, 0, .25)
button.Size = UDim2.new(amplitude, 0, amplitude, 0)
wait(0.05)
end
I do not know if I didn’t understand the question correctly, but to change the minimum value, you can just adjust the min value in math.clamp. If you need to retain that value though, you can just add a check that checks if the amplitude is less than your minimum value and if it is, change it to the minimum value. There is a chance I didn’t understand your question correctly, so if I didn’t, please explain it to me. Hopefully this helped.
You don’t need to add another math.clamp. The entire point of the math.clamp method is to have a minimum and maximum value for your number. That being said, you can simply change the 0 to whatever you have your min value to. Here is the line I am referring to:
local amplitude = math.clamp(music.PlaybackLoudness / maxLoudness, MIN_VALUE, .25)
Remember the minimum value I wanted is the default size does that mean local amplitude = math.clamp(music.PlaybackLoudness / maxLoudness, .25, .3) instead there isn’t something wrong with your solution I’m just asking since I never used math.clamp before until now
Well, the math.clamp() function takes in three parameters, the number x, the minimum value min, and the maximum value max. The logic it follows is:
If x is bigger than max, then the number returned is max.
If x is smaller than min, then the number returned is min.
If x is smaller than max but bigger than min (so within the range), then the number returned is x.
That being said, you can utilize this to your fitting. If you want to squish a value (so the range is between min and max, then you’d have to make your own function which changes the range.