How to set ImageTransparency Based on Static Sound

How would i set my Image Transparency based on the static sound?, But that the transparency cannot go up more than 1, since if the transparency is set to 1 it will no longer be possible to see

This is my current script : (everything is running inside a RenderStepped Function)

if closestPart then
		print("He is here")
		if not static1.IsPlaying then
			static1:Play()
			static2:Play()
			if static1.PlaybackLoudness <= MaxPlaybackLoudness then
			image.ImageTransparency = "0"..static1.PlaybackLoudness
			end
		end
if closestPart then
		print("He is here")
		if not static1.IsPlaying then
			static1:Play()
			static2:Play()
			if static1.PlaybackLoudness <= MaxPlaybackLoudness then
			image.ImageTransparency = 0 ..static1.PlaybackLoudness
			end
		end
1 Like
image.ImageTransparency = math.clamp(static1.PlaybackLoudness/100, 0.1, 0.9)

Use math.clamp(), you will likely need to change “100” to a value suitable to the audio, you want to divide it by double its average “PlaybackLoudness”. Such that the value returned by the division is 0.5 on average.

math.clamp() will use the value of the division if it lies between the two clamped values otherwise one of the clamped values is used instead.

1 Like

Alright, this worked, Just to confirm I would need to change the /100 to a Lower or high number so his Transparency rate is a bit more Noticiable?

Increase for lower transparency, decrease for higher transparency.

200-250 might work well.