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

Brickcolor wont change could someone help?

Im trying to get a script to work, but the problem is that in the output it only says 0, meaning it cant find the playbackloudness, can someone help me out please?

local RS = game:GetService('RunService')
local soundie = game.Workspace.Sound
local part = game.Workspace.Baseplate

while(wait())do
    if soundie.IsPlaying then
        print(soundie.PlaybackLoudness/1000)
        local randX = math.random(0,(soundie.PlaybackLoudness/1000))
        local randY = math.random(0,(soundie.PlaybackLoudness/1000))
        local randZ = math.random(0,(soundie.PlaybackLoudness/1000))

        part.Color = Color3.new(randX, randY, randZ)    
    end
end

this script if from another question (https://scriptinghelpers.org/questions/86786/how-do-i-change-the-brickcolor-based-on-playerbackloudness)

1 answer

✓ Accepted answer

Sound.PlaybackLoudness can only be read from the client, not the server.

-- LocalScript in StarterPlayer.StarterPlayerScripts
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.

-- Again, LocalScript in StarterPlayer.StarterPlayerScripts
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

0

Omg thank you so much! But just one more thing, how do you make it change when its kinda at a bass drop?

0

nevermind c:

0

It should work anyways.

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