local rs = game:GetService("RunService")
local plr = game.Players.LocalPlayer
local plrGui = plr:WaitForChild("PlayerGui")
local button = plrGui:WaitForChild("Settings"):WaitForChild("GUI"):WaitForChild("panels"):WaitForChild("ScrollingFrame"):WaitForChild("Visualizers"):WaitForChild("Club Floor"):WaitForChild("button")
button.Text = ("ON")
button.BackgroundColor3 = Color3.fromRGB(90,90,90)
local click = workspace:WaitForChild("clickeffect")
local sound = workspace:WaitForChild("Sound")
local parts = workspace:WaitForChild("parts")
local floor = parts:WaitForChild("Club Floor")
local pillars = workspace:WaitForChild("pillar")
local pillar1 = pillars.Model1.neon.Part
local pillar2 = pillars.Model2.neon.Part
local pillar3 = pillars.Model3.neon.Part
local pillar4 = pillars.Model4.neon.Part
local on = true
local lastSoundLevel = 0
local ColorSilent = Color3.fromRGB(0, 0, 0)
local ColorLoud = Color3.fromRGB(10, 162, 243)
rs.RenderStepped:Connect(function()
if on then
local difference = (sound.PlaybackLoudness / 2.2) - lastSoundLevel
lastSoundLevel = sound.PlaybackLoudness
difference /= 100
difference = math.clamp(difference, 0.62, 1)
local change = ColorSilent:Lerp(ColorLoud, difference)
floor.Color = change
pillar1.Color = change
pillar2.Color = change
pillar3.Color = change
pillar4.Color = change
end
end)
button.MouseButton1Click:Connect(function()
click:Play()
on = not on
if on then
button.Text = ("OFF")
button.BackgroundColor3 = Color3.fromRGB(50,50,50)
elseif not on then
button.Text = ("ON")
button.BackgroundColor3 = Color3.fromRGB(90,90,90)
floor.Color = ColorLoud
pillar1.Color = ColorLoud
pillar2.Color = ColorLoud
pillar3.Color = ColorLoud
pillar4.Color = ColorLoud
end
end)
I did some cleaning up but I believe your main issue lies here, you’re recording the PlaybackLoudness of the song when the script first executes (which is 0) but never re-recording it inside the RenderStepped, as you can see I’ve added a line of code which updates the lastSoundLevel variable from within the callback function connected to the RenderStepped event loop.
This script needs to go in StarterCharacterScripts because the references to the content within the PlayerGui folder are only valid while the player’s character is alive (when they die the PlayerGui folder is emptied and the GuiObjects inside the StarterGui folder are copied into the PlayerGui instance of the player).
If you want to avoid this behavior of ScreenGui instances you can disable the “ResetOnSpawn” property found within it, this will cause the contents of the PlayerGui to persist (not be removed) even when the player’s character dies/reloads/respawns.