I have this thing where I can make the blur and the camera go in with the music, but I was never able to make it so the image size changes depending on the bass or volume of the song being played?
I’m not sure entirely what you want.
If you just want a frame to change size, you could write something simple, for example if the volume is from a range of 0.0 to 1.0, then you change that to the size of the image. (Add anchor points of 0.5, 0.5 to center it)
local volumeSize = audio.Volume
local image = script.Parent.Image
image.Size = UDim2.new(volumeSize, 0, volumeSize, 0)
If you wanted those bars that go up with the music, then you could look at PlaybackLoudness. Here is the wiki article on it with an example.
Well, if you go the game link here, East Brickton [Season 2] - Roblox there have an intro of this sort, and I really like the idea, just don’t know how to execute it.
Edit: if you don’t understand what clamp is, it’s basically where you put in the desired value in the first position and then if it is between the range of the second and third position (0 to 1) then it will return that range. If it’s lower than the minimum value of 0, then it will return 0 and if it’s higher than 1 then it will return 1. It’s basically a rounding system that keeps it between a desired value so the frame doesn’t go past the size of the screen.
So, you would have an image label centered at the center of the screen by having the position (0.5, 0, 0.5, 0) and then the AnchorPoint set at (0.5, 0.5) and then use PlaybackLoudness to change the size of the frame.
Using the code from the wiki will help so this should give you a starting point.
local maxLoudness = 15
while true do
local amplitude = math.clamp(sound.PlaybackLoudness / maxLoudness, 0, 1)
bar.Size = UDim2.new(amplitude, 0, amplitude, 0)
wait(0.05)
end
This isn’t really working that well, any suggestions?
The only way to see how loud a sound is currently playing is via Sound.PlaybackLoudness, as far as I know. The PlaybackLoudness is a value between 0 and 1000, so try to play around a bit with its values. Again, take a look here to see what kind of results you would expect to see from it. It looks like it’s just gonna take some experimentation to find out what the best numbers to use are.
Alright I will try. 30Characters
I am still not getting this, the image bloats up but then never bloats down.
What does your code look like? Are you just using what’s on the wiki?
local maxLoudness = 10 local sound = script.Sound sound:Play() while true do local amplitude = math.clamp(sound.PlaybackLoudness / maxLoudness, 0.5, 0.5) script.Parent.Size = UDim2.new(amplitude, 0.1, amplitude, 0.5) wait(0.05) end
There’s a chance it might be the song at fault, but provide your code. Make sure it’s in a loop.
Edit: it’s your min and max clamp values. BreadyToCrumble beat me to it since I’m on mobile.
Change the (0.5, 0.5)
to (0, 0.5)
.
Your bound right now are only between 0.5 and 0.5, which results in returning only 0.5.
edit: gg Advanced
Nothing Character30limitsCode
What if you try setting the size to this?
local amplitude = math.clamp(sound.PlaybackLoudness/1000, 0.2, 0.5)
script.Parent.Size = UDim2.new(amplitude, 0, amplitude, 0)
That converts PlaybackLoudness to a number between 0 and 1, then bounds it between 0.2 and 0.5.
Print the amplitude and try seeing what the values are. Try messing around with the maxLoudness as I don’t see anything wrong with it if you’re following the example I gave.
Oohhh, we got something going!
Nice! Like AdvancedDrone said, print the value of PlaybackLoudness/1000
and see what it is throughout the song. Play around with the bounds a bit and see what you like.
Glad we could get something working for you!
The only issue is, its capping off, I don’t want there to really be a cap off.
To prevent a cap off, you can change the bounds in math.clamp. The second and third arguments, 0.2
and 0.5
are your lower and upper “caps” (bounds) respectively.
Nevermind I fixed the cap off.