#Help with script according to PlayBackLoudness

1 messages · Page 1 of 1 (latest)

placid moon
#

hey everyone,
i’m working on a script where a part spins based on how loud a sound is (using PlaybackLoudness), but it’s not really working the way i expected.

the idea is that the louder the sound, the faster the part should spin. the spinning itself works, but the speed doesn’t seem to change with the loudness. i’m not sure if i’m reading the right PlaybackLoudness, or if i’m even using it correctly — especially since i’m trying this with a Humanoid.

can anyone help me figure out what might be wrong with my logic or suggest what i could try instead?

local speed = -90
local angle = 0

game:GetService("RunService").Heartbeat:Connect(function(dt)
    angle = (angle + speed * dt) % 360
    attachment.Orientation = Vector3.new(0, angle, 0)
end)

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local baseSpeed = speed

humanoid:GetPropertyChangedSignal("PlaybackLoudness"):Connect(function()
    local loudness = humanoid.PlaybackLoudness
    local speedMultiplier = math.clamp(loudness / 50, 0.5, 3)
    speed = baseSpeed * speedMultiplier
end)```

i’m mainly just trying to understand how to properly use PlaybackLoudness and make sure i’m getting it from the right object. go easy on me, i’m still learning and i am dumb ![crying](https://cdn.discordapp.com/emojis/1085957307655000165.webp?size=128 "crying")
ionic marsh
#

humanoid doesn't have playbackloudness property ?

worthy hollow
#

Humanoid has no playback loadness property, instead grab the sound instance

#

bruh wait you answer sorry I wasnt looking

ionic marsh
#

could use the sound's playbackloudness to get a waveform but isn't really how "loud" it is despite the name, and won't pick up any nearby sounds. for that you'd need to use the new audio api https://create.roblox.com/docs/reference/engine/classes/AudioListener -> https://create.roblox.com/docs/reference/engine/classes/AudioAnalyzer#RmsLevel but it all always depends on exactly what you're trying to do

Records an audio stream from its surrounding
Class.AudioEmitter|AudioEmitters in the 3D world.

Takes measurements from audio streams that are connected to it via one or more
Class.Wire|Wires.

placid moon
#

i changed it but it still doesnt work

local speed = -180

local angle = 0
game:GetService("RunService").Heartbeat:Connect(function(dt)
    angle = (angle + speed * dt) % 360
    attachment.Orientation = Vector3.new(0, angle, 0)
end)

local Players = game:GetService("Players")
local SoundService = game:GetService("SoundService")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local sound = character:WaitForChild("Sound")

local baseSpeed = speed

sound:GetPropertyChangedSignal("PlaybackLoudness"):Connect(function()
    local loudness = sound.PlaybackLoudness
    local speedMultiplier = math.clamp(loudness / 50, 0.5, 3)
    speed = baseSpeed * speedMultiplier
end)```
#

it isnt for nearby sounds, its for the music on the model

worthy hollow
#

look in those documentation Pyro sent, its pretty cool

granite sluice
#

i mean

granite sluice
#

where in studio

placid moon
#

its in the model named soundvis

granite sluice
#

local?

placid moon
#

no

granite sluice
#

well ur using Players.LocalPlayer

#

?

placid moon
#

uh

worthy hollow
#

no you can create a "wire" with a parent and source with a target and it will listen and analyze using the classes in the documentation

ionic marsh
#

that's the new sound api, it's pretty neat, you can do all sorts of audio work with it

#

but the old sound stuff is just as good too

worthy hollow
#

yeah just finish with local loudness = analyzer.RmsLevel and it works

placid moon
#

never heard of any of that crying

ionic marsh
worthy hollow
#

I just heard of it too

#

yeah it does fire

#

analyzer:GetPropertyChangedSignal("RmsLevel")

ionic marsh
#

the rest you can figure out by messing with it

#

it's main use though is interacting with voice chat

#
#
placid moon
#

thats overwhelming

#

im gonna try tho

ionic marsh
placid moon
#

sure ok

#

but should it be a local or server script

#

i think i got things wrong

ionic marsh
#

roblox uses this in their sample ```lua
local maxLoudness = 30

local amplitude = math.clamp(sound.PlaybackLoudness / maxLoudness, 0, 1)```

ionic marsh
worthy hollow
#

"This property changes more often than the framerate and does not fire changed events. On the server, this property is always 0." mb for the mis info lol

worldly oarBOT
#

studio** You are now Level 3! **studio