PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

EmitterSize

Sound

float

The minimum distance at which a 3D Sound (direct child of a BasePart or Attachment) will begin to attenuate (decrease in volume).

Sounds parented to a BasePart or Attachment that are descendants of the Workspace are considered 3D sounds and their volume whilst playing is dependent on the distance between the client’s sound listener (Camera position by default) and the Sound’s parent. Two properties influence this behavior Sound/EmitterSize and Sound/RollOffMode.

The way the Sound attenuates (fades out) after the distance between the listener and the sound exceeds the Sound/EmitterSize is determined by Sound/RollOffMode.


Code Samples


Music Playing Part

The code in this sample demonstrates how a sound parented to a Part or Attachment will play locally and experience volume drop off the further the player’s camera is away from the part.

A part is instanced, and a sound is instanced and parented to the part. A click detector is set up on the part that will check if the sound is playing, using Sound.IsPlaying and play or stop the sound depending.

-- create a part
local part = Instance.new("Part")
part.Anchored = true
part.Position = Vector3.new(0, 3, 0)
part.BrickColor = BrickColor.new("Bright red")
part.Name = "MusicBox"
part.Parent = game.Workspace

-- create a sound
local sound = Instance.new("Sound", part)
sound.SoundId = "rbxassetid://301964312" 
sound.EmitterSize = 5 -- decrease the emitter size (for earlier volume drop off)
sound.Looped = true

-- create a click detector
local clickDetector = Instance.new("ClickDetector", part)
clickDetector.MouseClick:Connect(function()
	-- toggle the sound playing / not playing
	if not sound.IsPlaying then
		part.BrickColor = BrickColor.new("Bright green")	
		sound:Play()
	else
		part.BrickColor = BrickColor.new("Bright red")	
		sound:Stop()
	end
end)