How would I make a screen GUI's transparency tween depending on how loud an audio is?

I want to learn how to make a screen GUI’s transparency tween depending on how loud an audio is, for example… if a bomb is ticking, the screen would go black for every moment the ticking stops, whereas the screen is normal for each time there IS a tick. Another example would be having a screen GUI’s transparency tween throughout a regular song, sort of how games have the FOV tween depending on how loud a song is on their game intro.

I’ve tried looking on the internet to things related to syncing stuff with audio & have not had much luck. I’d love if someone could help steer me in the right direction (also I’m pretty new to scripting so idk how basic or advanced something like this is)

1 Like

It is pretty new for this concept.This is tough,because roblox dont have this loudness thing.But you can try do this

While wait(1) do
IF LOUDNESS == A CERTAIN NUMBER THEN
— PUT YOUR VARAIBLES IN HERE
END
End

1 Like

You don’t necessarily need to sync it with the audio. Unless the ticking is random.

1 Like

You could make the ui’s transparency property equals to the volume property of the audio.

1 Like

Perhaps you could try this:

game:GetService("RunService").RenderStepped:Connect(function()
	frame.BackgroundTransparency = 1 - sound.PlaybackLoudness * 0.0003   
end)

what this code does, is basically sets a frame’s transparency depending on the loudness of the audio( you can modify the 0.0003 number at the end to your preferences, its basically how hard you want it to be, you can try this code out. Maybe that’s what you’re looking for.

2 Likes

This definitely seems like the right approach but I can’t seem to figure stuff out. What am I doing wrong here?

I know I have to remove the audio outside of the function already but I’m not sure how to go about it.

local plr = game:GetService("Players")
game:GetService("RunService").RenderStepped:Connect(function()
	local screenGui = Instance.new("ScreenGui")
	screenGui.Parent = plr.LocalPlayer:WaitForChild("PlayerGui")  
	local frame = Instance.new("Frame")
	frame.Size = UDim2.new(1, 0, 1, 0)  
	frame.Position = UDim2.new(0.5, 0, 0.5, 0) 
	frame.AnchorPoint = Vector2.new(0.5, 0.5) 
	frame.Parent = screenGui  
	local sound = Instance.new("Sound")
	sound.SoundId = "rbxassetid://6143351020"
	sound.Parent = plr.LocalPlayer 
	sound:Play()
	frame.BackgroundTransparency = 1 - sound.PlaybackLoudness * 0.0003   
end)

1 Like

try creating a frame, not by using a script.

(sorry for not replying for some time, i was busy with school and all that stuff)