Event from reaching a specific audio playback loudness

I’m trying to clone an object when an audio gets loud enough

For some reason my script isn’t working, and I don’t know what I did wrong.

This is the script:

local part = game.Workspace.Part
local Sound = game.Workspace.Sound
if Sound.PlaybackLoudness > 100 then
	local clonedObject = part:Clone()
	clonedObject.Parent = game.Workspace
	clonedObject.Position = Vector3.new(-55.1, 5, 23.1)
end

Since it’s not working, I’m pretty sure I didn’t do something correctly, but I have no idea what it is

1 Like

use :GetPropertyChangedSignal() to detect changes for a specific property.

your code would work, it’s just that it would only run once.

if you’re a bit stuck, here’s how you can go about doing it:

Sound:GetPropertyChangedSignal("PlaybackLoudness"):Connect(function()
    -- do something
end)

How would I specify how loud the playbackloudness needs to be?

Sound:GetPropertyChangedSignal("PlaybackLoudness"):Connect(function()
    if Sound.PlaybackLoudness > 100 then
        print("the audio is pretty loud")
    end
end)

Sound.PlaybackLoudness = -- whatever value you want to set it to

It’s still not working, should this be in a local script or a normal script?

can you show me the code you wrote?

local run = game:GetService("RunService")

local part = workspace.Part
local sound = workspace.Sound

if script:IsA("Script") then
	run.Heartbeat:Connect(function()
		if sound.PlaybackLoudness > 100 then
			local partClone = part:Clone()
			partClone.Position = Vector3.new(-55.1, 5, 23.1)
			partClone.Parent = game.Workspace
		end
	end)
elseif script:IsA("LocalScript") then
	run.RenderStepped:Connect(function()
		if sound.PlaybackLoudness > 100 then
			local partClone = part:Clone()
			partClone.Position = Vector3.new(-55.1, 5, 23.1)
			partClone.Parent = game.Workspace
		end
	end)
end

Wasn’t sure what type of script you were using.

It worked, but I can’t edit the cloned part using the script, is there a reason for this?

local run = game:GetService("RunService")

local part = game.Workspace.Part
local sound = workspace.Sound

if script:IsA("Script") then
	run.Heartbeat:Connect(function()
		if sound.PlaybackLoudness > 900 then
			local partClone = part:Clone()
			partClone.Position = Vector3.new(-55.1, 5, 23.1)
			partClone.Parent = game.Workspace
			partClone.Script.Disabled = false
			wait(3)
			partClone:Destroy()
		end
	end)
elseif script:IsA("LocalScript") then
	run.RenderStepped:Connect(function()
		if sound.PlaybackLoudness > 900 then
			local partClone = part:Clone()
			partClone.Position = Vector3.new(-55.1, 5, 23.1)
			partClone.Parent = game.Workspace
			partClone.Script.Disabled = false
			partClone.Size = partClone.Size + Vector3.new(1,1,1)
			wait(3)
			partClone:Destroy()
		end
	end)
end

As you can see, I added a 3 second wait and then destroyed the part. It doesn’t work though, any idea why?