somehow, setting the size of the WhiteCylinder is like, 25x more expensive than setting BlackCylinders size, when it has less calculations to do
and its not even the calculations its straight up setting the size itself
so this really confuses me
![]()
Full script
--!optimize 2
repeat task.wait() until script.Parent.Enabled
local RS = game:GetService("RunService")
local mainscript = script.Parent
local Event = mainscript:FindFirstChild("Event")
local Query = mainscript:FindFirstChild("Query")
local whiteCylinder
local blackCylinder
local sound
local analyzer
local root
local listener
local out
local cam = workspace.CurrentCamera
local baseFOV = cam.FieldOfView
local currentFOV = cam.FieldOfView
local eventconnection
local renderconnection
local v3 = Vector3
local v3n = Vector3.new
local baseWhite = v3n(0.3,2,2)
local baseBlack = v3n(0.2,3,3)
local profilebegin, profileend = debug.profilebegin, debug.profileend
local min, max = math.min, math.max
local SETTINGS = {
VOLUME = 0.75,
BOOSTER = 1,
RANGES = {0, 550, 725},
COLORS = {
Color3.fromRGB(0,0,0),
Color3.fromRGB(80, 0, 255),
Color3.fromRGB(100, 90, 255)
},
FOV_BOBBING = true,
MODE = "LEGACY"
}
SETTINGS.MODE=mainscript:GetAttribute("MODE")
SETTINGS.MIN_RANGE = mainscript:GetAttribute("MIN_RANGE")
SETTINGS.MAX_RANGE = mainscript:GetAttribute("MAX_RANGE")
SETTINGS = Query:InvokeServer()
function clerp(cur, new, alpha)
return cur + (new - cur) * alpha
end
local function generateDistanceCurve(minDist: number, maxDist: number, steps: number?)
local step: number = tonumber(steps) or 20
local curve = {}
local range = maxDist - minDist
for i = 0, step do
local t = i / step
local distance = minDist + t * range
local value = (1 - t)^2
curve[distance] = value
end
return curve
end
local function wireUp(source: Instance, target: Instance): Wire
local wire = Instance.new("Wire")
wire.Parent = target
wire.SourceInstance = source
wire.TargetInstance = target
return wire
end
function find(parent: Instance, name: string, kind: string)
local obj
repeat
for _,v in pairs(parent:GetChildren()) do
if v.Name == name and v:IsA(kind) then
obj = v
end
end
task.wait()
until obj
return obj
end
function init()
if not cam:FindFirstChild("AUDIO_LISTENER") then
listener = Instance.new("AudioListener")
listener.Parent = cam
listener.Name = "AUDIO_LISTENER"
listener:SetDistanceAttenuation(generateDistanceCurve(SETTINGS.MIN_RANGE, SETTINGS.MAX_RANGE))
end
if not cam:FindFirstChild("AUDIO_OUT") then
out = Instance.new("AudioDeviceOutput")
out.Parent = cam
out.Name = "AUDIO_OUT"
end
wireUp(listener, out)
end
init()
local lastWhiteSize = v3n(0,0,0)
local lastBlackSize = v3n(0,0,0)
local lastWhiteColor = Color3.new(0,0,0)
local SIZE_EPSILON = 0.01
local COLOR_EPSILON = 0.01
eventconnection = Event.OnClientEvent:Connect(function(kind, args)
if kind == "SettingsUpdate" then
SETTINGS = args
if listener then
listener:SetDistanceAttenuation(generateDistanceCurve(SETTINGS.MIN_RANGE, SETTINGS.MAX_RANGE))
end
end
end)
renderconnection = RS.RenderStepped:Connect(function()
profilebegin("FindMissingReferences")
if not whiteCylinder then
whiteCylinder = find(mainscript, "WhiteCylinder", "BasePart")
end
if not blackCylinder then
blackCylinder = find(mainscript, "BlackCylinder", "BasePart")
end
if not root then
root = find(mainscript.Parent, "HumanoidRootPart", "BasePart")
end
if not sound then
if SETTINGS.MODE == "LEGACY" then
sound = find(root, "AUDIO", "Sound")
elseif SETTINGS.MODE == "NEW" then
sound = find(root, "AUDIO", "AudioPlayer")
end
end
if not analyzer and sound and SETTINGS.MODE=="NEW" then
analyzer = find(sound, "AUDIO_ANALYZER", "AudioAnalyzer")
end
profileend()
if sound and root and blackCylinder and whiteCylinder and sound.IsPlaying then
profilebegin("CalculateLoudness")
local peak = SETTINGS.MODE=="NEW" and (analyzer.PeakLevel * 1000 * 0.75 / sound.Volume) or sound.PlaybackLoudness
local loudness = peak / 50 * SETTINGS.BOOSTER
profileend()
profilebegin("ResizeCylinders")
profilebegin("CalculateAlphaAndLerp")
local alpha = min(loudness / 87.5, 1)
local whitesize = whiteCylinder.Size
local blacksize = blackCylinder.Size
local targetWhite = v3n(baseWhite.X, baseWhite.Y + loudness, baseWhite.Z + loudness)
local targetBlack = v3n(baseBlack.X, baseBlack.Y + loudness, baseBlack.Z + loudness) * 1.065
whitesize = clerp(whitesize, targetWhite, alpha)
blacksize = clerp(blacksize, targetBlack, alpha / 3)
profileend()
profilebegin("ApplySizesAndClampBlack")
profilebegin("Setting White Size")
local whiteDiff = whitesize - lastWhiteSize
local whiteDiffSq = whiteDiff.X*whiteDiff.X + whiteDiff.Y*whiteDiff.Y + whiteDiff.Z*whiteDiff.Z
if whiteDiffSq > SIZE_EPSILON*SIZE_EPSILON then
whiteCylinder.Size = whitesize
lastWhiteSize = whitesize
end
profileend()
profilebegin("Setting Black Size")
local blackY = max(blacksize.Y, lastWhiteSize.Y + 1)
local blackZ = max(blacksize.Z, lastWhiteSize.Z + 1)
local blackFinal = v3n(blacksize.X, blackY, blackZ)
local blackDiff = blackFinal - lastBlackSize
local blackDiffSq = blackDiff.X*blackDiff.X + blackDiff.Y*blackDiff.Y + blackDiff.Z*blackDiff.Z
if blackDiffSq > SIZE_EPSILON*SIZE_EPSILON then
blackCylinder.Size = blackFinal
lastBlackSize = blackFinal
end
profileend()
profileend()
profileend()
profilebegin("UpdateColor")
local pl = loudness * 50
local color = SETTINGS.COLORS[#SETTINGS.COLORS]
for i = 1, #SETTINGS.RANGES - 1 do
local low, high = SETTINGS.RANGES[i], SETTINGS.RANGES[i + 1]
if pl >= low and pl <= high then
local t = (pl - low) / (high - low)
color = SETTINGS.COLORS[i]:Lerp(SETTINGS.COLORS[i + 1], t)
break
end
end
local dr = color.R - lastWhiteColor.R
local dg = color.G - lastWhiteColor.G
local db = color.B - lastWhiteColor.B
if dr*dr + dg*dg + db*db > COLOR_EPSILON*COLOR_EPSILON then
whiteCylinder.Color = color
lastWhiteColor = color
end
profileend()
profilebegin("FOVBobbing")
if SETTINGS.FOV_BOBBING then
local distance = (cam.CFrame.Position - root.Position).Magnitude
local factor = ((loudness / 7.5) ^ 2)
local t = (distance - SETTINGS.MIN_RANGE) / (SETTINGS.MAX_RANGE - SETTINGS.MIN_RANGE)
t = math.min(t, 1)
local targetFOV = baseFOV - factor * (1 - t)
currentFOV = currentFOV + (targetFOV - currentFOV) * (alpha*1.2)
cam.FieldOfView = currentFOV
end
profileend()
end
end)
script.Destroying:Connect(function()
RS = nil
Event = nil
whiteCylinder = nil
blackCylinder = nil
sound = nil
analyzer = nil
root = nil
cam = nil
baseFOV = nil
eventconnection:Disconnect()
renderconnection:Disconnect()
baseWhite = nil
baseBlack = nil
min, max = nil, nil
table.clear(SETTINGS)
end)


