Sound.PlaybackLoudness can only be read from the client, not the server.
02 | local RS = game:GetService( 'RunService' ) |
03 | local soundie = game.Workspace.Sound |
04 | local part = game.Workspace.Baseplate |
07 | if soundie.IsPlaying then |
08 | local pLoudness = soundie.PlaybackLoudness |
10 | local randX = math.random( 0 , pLoudness) / 100 |
11 | local randY = math.random( 0 , pLoudness) / 100 |
12 | local randZ = math.random( 0 , pLoudness) / 100 |
14 | part.Color = Color 3. new(randX, randY, randZ) |
16 | RS.RenderStepped:Wait() |
All the 0's in the output were being read from the server, not the client. The server doesn't actually play the sound, it tells the clients to play the sound. The following script should work.
Also, depending on the sound, the baseplate will flash. The following code fixes the flashing by tweening the colors.
02 | local RS = game:GetService( 'RunService' ) |
03 | local tweenService = game:GetService( 'TweenService' ) |
06 | local easingStyle = Enum.EasingStyle.Linear |
07 | local easingDirection = Enum.EasingDirection.In |
09 | local colorTweenInfo = TweenInfo.new(waitTime, easingStyle, easingDirection, 0 , false , 0 ) |
11 | local soundie = game.Workspace.Sound |
12 | local part = game.Workspace.Baseplate |
14 | local function getNewColor() |
15 | local pLoudness = soundie.PlaybackLoudness |
17 | local randX = math.random( 0 , pLoudness) / 100 |
18 | local randY = math.random( 0 , pLoudness) / 100 |
19 | local randZ = math.random( 0 , pLoudness) / 100 |
21 | local newColor = Color 3. new(randX, randY, randZ) |
25 | local function createColorTween() |
26 | local newColor = getNewColor() |
27 | local tween = tweenService:Create(part, colorTweenInfo, { Color = newColor } ) |
33 | if soundie.IsPlaying then |
34 | local tween = createColorTween() |
36 | tween.Completed:Wait() |
Just be sure to warn your players about flashing lights.