I want the image gui to bounce with the music

i would like to know how to make the image bounce with the music?
(please help me)

2 Likes

You can use Sound.PlaybackLoudness for this. Once your desired loudness has been reached, bounce the image using a Tween Animation on it.

Since :GetPropertyChangedSignal("PlaybackLoudness") does not work, you’ll have to use a loop. Generally speaking, while wait() do loops aren’t great for performance. If you’re having performance issues because of the loop, you can increase the time between loops for better performance at the cost of less accurate sound detection.

local TweenService = game:GetService("TweenService")
local BounceLoudness = 30 --Number between 0 and 1000, will need to be tweaked depending on how loud your sound is and when you want it to bounce (like a bass drop, etc.).
local CurrentlyAnimating = false --A debounce in case you bind it to an event instead of a while loop.
while task.wait(1/60) do --:GetPropertyChangedSignal("PlaybackLoudness") does not work so you'll have to use a while loop.
	if Sound.PlaybackLoudness >= BounceLoudness and not CurrentlyAnimating then
		CurrentlyAnimating = true
		local TweenInfo = TweenInfo.new(
			0.5, -- Time
			Enum.EasingStyle.Bounce, -- EasingStyle
			Enum.EasingDirection.InOut, -- EasingDirection
			0, -- RepeatCount (when less than zero the tween will loop indefinitely)
			true, -- Reverses (tween will reverse once reaching it's goal)
			0 -- DelayTime
		)
		local TweenBounce = TweenService:Create(ImageLabel, TweenInfo, {Rotation = NUMBER, Position = UDim2.new(XScale, XOffset, YScale, YOffset) })--Animate the ui using a tween.
		TweenBounce:Play()
		TweenBounce.Completed:Wait() --Wait for the animation to finish
		TweenBounce:Destroy()
		CurrentlyAnimating = false
	end
end

You’ll probably want to use random numbers for the TweenGoals (Rotation and Position) so it doesn’t feel repetitive. You can also multiply the Position by the PlaybackLoudness for some scaling effects (louder music makes it bounce higher, quieter music makes it bounce lower). It will take a bit of tweaking with the TweenGoals, TweenTime, and PlaybackLoudness to get a good result.

1 Like

Since when were while wait() loops non performant? It mainly depends whats inside those loops that causes the perforance drop.

Also since the changes are very frequent, A tween every microsecond is very expensive, is better just to set the size with .Position