Make playback Loudness trigger particles

Hi, so I have a code here. I have no idea how to script lua, all I did is get a script from a youtube video and paste these particle emitters from a button. How do I make it so it’ll trigger when the audio is loud.

Here is my code, I don’t expect anyone to correct it since I think its all wrong but any help to make this work is appreciated!

game:GetService("RunService").Heartbeat:Connect(function()
	local loud = workspace.Music.PlaybackLoudness * 0.05 + 1
		for i,v in pairs(game.Workspace.FW3:GetChildren())
		do	
			if v.Name == "FW_3"
			then
				spawn(function()
					v.FW.F1.P1.Enabled = true
					v.FW.F1.P2.Enabled = true
					v.FW.F1.P3.Enabled = true
					v.FW.F1.P4.Enabled = true
					v.FW.F1.P5.Enabled = true
					v.FW.F1.Sound:Play()
					v.FW.F2.P1.Enabled = true
					v.FW.F2.P2.Enabled = true
					v.FW.F2.P3.Enabled = true
					v.FW.F2.P4.Enabled = true
					v.FW.F2.P5.Enabled = true
					wait(0.2)
					v.FW.F1.P1.Enabled = false
					v.FW.F1.P2.Enabled = false
					v.FW.F1.P3.Enabled = false
					v.FW.F1.P4.Enabled = false
					v.FW.F1.P5.Enabled = false
					v.FW.F1.Sound:Pause()
					v.FW.F2.P1.Enabled = false
					v.FW.F2.P2.Enabled = false
					v.FW.F2.P3.Enabled = false
					v.FW.F2.P4.Enabled = false
					v.FW.F2.P5.Enabled = false
					v.FW.F2.Sound:Pause()
					v.FW.F3.P1.Enabled = true
					v.FW.F3.P2.Enabled = true
					v.FW.F3.P3.Enabled = true
					v.FW.F3.P4.Enabled = true
					v.FW.F3.P5.Enabled = true
					v.FW.F3.Sound:Play()
					wait(0.2)
					v.FW.F3.P1.Enabled = false
					v.FW.F3.P2.Enabled = false
					v.FW.F3.P3.Enabled = false
					v.FW.F3.P4.Enabled = false
					v.FW.F3.P5.Enabled = false
					v.FW.F3.Sound:Pause()

You need to end each statement with a end

game:GetService("RunService").Heartbeat:Connect(function()	
	if workspace.Music.PlaybackLoudness < 2 then --// If the playback loudness is larger than 2, it will return false to the function, stopping the function to progress further
		return false
	end
	
	for i,v in pairs(game.Workspace.FW3:GetChildren()) do	
		if not v.Name == "FW_3" then
			spawn(function()
				v.FW.F1.P1.Enabled = true
				v.FW.F1.P2.Enabled = true
				v.FW.F1.P3.Enabled = true
				v.FW.F1.P4.Enabled = true
				v.FW.F1.P5.Enabled = true
				v.FW.F1.Sound:Play()
				v.FW.F2.P1.Enabled = true
				v.FW.F2.P2.Enabled = true
				v.FW.F2.P3.Enabled = true
				v.FW.F2.P4.Enabled = true
				v.FW.F2.P5.Enabled = true
				wait(0.2)
				v.FW.F1.P1.Enabled = false
				v.FW.F1.P2.Enabled = false
				v.FW.F1.P3.Enabled = false
				v.FW.F1.P4.Enabled = false
				v.FW.F1.P5.Enabled = false
				v.FW.F1.Sound:Pause()
				v.FW.F2.P1.Enabled = false
				v.FW.F2.P2.Enabled = false
				v.FW.F2.P3.Enabled = false
				v.FW.F2.P4.Enabled = false
				v.FW.F2.P5.Enabled = false
				v.FW.F2.Sound:Pause()
				v.FW.F3.P1.Enabled = true
				v.FW.F3.P2.Enabled = true
				v.FW.F3.P3.Enabled = true
				v.FW.F3.P4.Enabled = true
				v.FW.F3.P5.Enabled = true
				v.FW.F3.Sound:Play()
				wait(0.2)
				v.FW.F3.P1.Enabled = false
				v.FW.F3.P2.Enabled = false
				v.FW.F3.P3.Enabled = false
				v.FW.F3.P4.Enabled = false
				v.FW.F3.P5.Enabled = false
				v.FW.F3.Sound:Pause()
			end)
		end
	end
end)

It’s also a bad practice to use repeat code, you should make it into a function instead
The original code did not check for loudness, thus it will play the sound no matter the loudness

1 Like