✓ Accepted answer
Sound.PlaybackLoudness can only be read from the client, not the server.
local RS = game:GetService('RunService')
local soundie = game.Workspace.Sound
local part = game.Workspace.Baseplate
while true do
if soundie.IsPlaying then
local pLoudness = soundie.PlaybackLoudness
print(pLoudness)
local randX = math.random(0, pLoudness) / 100
local randY = math.random(0, pLoudness) / 100
local randZ = math.random(0, pLoudness) / 100
part.Color = Color3.new(randX, randY, randZ)
end
RS.RenderStepped:Wait()
end
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.
local RS = game:GetService('RunService')
local tweenService = game:GetService('TweenService')
local waitTime = 0.25
local easingStyle = Enum.EasingStyle.Linear
local easingDirection = Enum.EasingDirection.In
local colorTweenInfo = TweenInfo.new(waitTime, easingStyle, easingDirection, 0, false, 0)
local soundie = game.Workspace.Sound
local part = game.Workspace.Baseplate
local function getNewColor()
local pLoudness = soundie.PlaybackLoudness
print(pLoudness)
local randX = math.random(0, pLoudness) / 100
local randY = math.random(0, pLoudness) / 100
local randZ = math.random(0, pLoudness) / 100
local newColor = Color3.new(randX, randY, randZ)
return newColor
end
local function createColorTween()
local newColor = getNewColor()
local tween = tweenService:Create(part, colorTweenInfo, {Color = newColor})
return tween
end
while true do
if soundie.IsPlaying then
local tween = createColorTween()
tween:Play()
tween.Completed:Wait()
end
end
Just be sure to warn your players about flashing lights.
3 comments
Omg thank you so much! But just one more thing, how do you make it change when its kinda at a bass drop?
nevermind c:
It should work anyways.