Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to size a part according to music?

Say that you have a part. How would you change some of it's Vector3 values (i.e. changing the Y Axis of the size for the part with the music being played). Sort of like audio visuals. Thanks.

3 comments

0

do you have any attempts?

0

Usually values are changed by using the = operator.

0

Which value are you aiming at doing this with: PlaybackLoudness, Volume, Pitch, etc.?

2 answers

✓ Accepted answer

Alrighty, so this is actually pretty simple. All you would have to do is use PlaybackLoudness to resize the part. Here is an example.


local part = workspace:WaitForChild('Part');
local sound = part:WaitForChild('Sound');
part.Anchored = true;

while wait() do
part.Size = Vector3.new(5,sound.PlaybackLoudness/5,5);
end

Roblox Has The Same thing and they do it with guis too. Here is my script it uses four different ones and makes it look like a sound wave while playing an audio I made!

-- to be placed in StarterPlayer > StarterPlayerScripts
 
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local bar1 = game.Workspace.AudioSpectrum.Part1
local bar2 = game.Workspace.AudioSpectrum.Part2
local bar3 = game.Workspace.AudioSpectrum.Part3
local bar4 = game.Workspace.AudioSpectrum.Part4
local bar5 = game.Workspace.AudioSpectrum.Part5
local bar6 = game.Workspace.AudioSpectrum.Part6
local bar7 = game.Workspace.AudioSpectrum.Part7
local bar8 = game.Workspace.AudioSpectrum.Part8
local sound = Instance.new("Sound")
local maxLoudness = 75000

bar1.Size = Vector3.new(1, 1, 1)
bar2.Size = Vector3.new(1, 1, 1)
bar3.Size = Vector3.new(1, 1, 1)
bar4.Size = Vector3.new(1, 1, 1)
bar5.Size = Vector3.new(1, 1, 1)
bar6.Size = Vector3.new(1, 1, 1)
bar7.Size = Vector3.new(1, 1, 1)
bar8.Size = Vector3.new(1, 1, 1)
sound.SoundId = "rbxassetid://2420742510"
sound.Looped = true
sound:Play()
sound.Parent = game.Workspace.AudioSpectrum
sound.Volume = 1
sound.PlaybackSpeed = 1.1 
 
while true do
	local amplitude = math.clamp(sound.PlaybackLoudness / maxLoudness, 0, 0.5)
	bar1.Size = Vector3.new(0.5, amplitude * 5000, 0.5)
	wait(0.0000001)
	bar2.Size = Vector3.new(0.5, amplitude * 4000, 0.5)
	wait(0.0000001)
	bar3.Size = Vector3.new(0.5, amplitude * 6000, 0.5)
	wait(0.0000001)
	bar4.Size = Vector3.new(0.5, amplitude * 3000, 0.5)
	wait(0.0000001)
	bar5.Size = Vector3.new(0.5, amplitude * 4000, 0.5)
	wait(0.0000001)
	bar6.Size = Vector3.new(0.5, amplitude * 5000, 0.5)
	wait(0.0000001)
	bar7.Size = Vector3.new(0.5, amplitude * 2000, 0.5)
	wait(0.0000001)
	bar8.Size = Vector3.new(0.5, amplitude * 5000, 0.5)
	wait(0.0000001)
end

This discussion is preserved as it was. New answers, comments, and votes are closed.