Sound emitter playing non-spatially (everywhere without falloff)

I have a sound emitter, in an attatchment, in a basepart. It has some audios. When someone hits the proxy prompt, it swaps out the song. No issue there.

Except for the fact that no matter what I do, it just decides not to occlude, not to fall off, but to just play EVERYWHERE.

Here’s the script, and some images;

local emitter = container.Attachment:FindFirstChildOfClass("AudioEmitter")
local sounds = {}
local currentSound = nil
local textLabel = container:FindFirstChild("Billboard") and container.Billboard:FindFirstChildOfClass("BillboardGui") and container.Billboard:FindFirstChildOfClass("BillboardGui"):FindFirstChildOfClass("Frame"):FindFirstChildOfClass("TextLabel")
local prompt = container:FindFirstChildOfClass("ProximityPrompt")

if emitter then
	for _, obj in ipairs(emitter:GetChildren()) do
		if obj:IsA("Sound") then
			table.insert(sounds, obj)
			obj.EmitterSize = 10
		end
	end
end

local function getRandomSound(exclude)
	local pool = {}
	for _, sound in ipairs(sounds) do
		if sound ~= exclude then
			table.insert(pool, sound)
		end
	end
	if #pool == 0 then return exclude end
	return pool[math.random(1, #pool)]
end

local function playSound(sound)
	if currentSound then
		currentSound:Stop()
	end
	currentSound = sound

	currentSound.Looped = true
	currentSound.EmitterSize = 10
	currentSound:Play()

	if textLabel then
		textLabel.Text = currentSound.Name
	end
end

if emitter then
	playSound(getRandomSound(nil))
end

if prompt then
	prompt.Triggered:Connect(function()
		local newSound = getRandomSound(currentSound)
		playSound(newSound)
	end)
end




d235f11224fbefc74965d8a904d93461

I genuinely don’t know what’s going on here.

The issue is that you are using Sound instances, when you should be using AudioPlayers.
Sound instances are the traditional way to do sounds, but you aren’t able to use them in conjunction with the new audio emitters.

The sound objects are parented to a non-basepart object (in this case, an AudioEmitter), so the audio plays from everywhere.

I would recommend replacing all Sound instances with a AudioPlayer, then connect the audio players to the AudioEmitter using a Wire (another instance)

Yeah, this worked. Thank you! Marking this as solution now.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.