Sound is not spatial [HELP]

I want spatial sounds for the generator and lamp, but they do not work and instead makes it so I can hear it constantly no matter where I move my character. I would also like to someone explain, if my code would make it a client- or server-sided sound play.

Goal

The further I move my character/camera (whichever method most popular games usually use), the further the audio of both sounds will independently become as I or someone else becomes more distant from the audio source.

Issue

It does not become a spatial sound.

Concern

Would my code have made the sounds client- or server-sided?

Code
-- Variables
local light = workspace.Lamp.Base.light.PointLight -- Path to the PointLight
local lamp = workspace.Lamp.Base.light -- Path to the part
local prompt = workspace.Lamp.generator.Attachment.ProximityPrompt -- Path to the prompt

-- Sounds
-- Light Sound
local lightSound = Instance.new("Sound") -- Creates a new Sound instance
lightSound.SoundId = workspace.Lamp.Base.light.Sound.SoundId -- Sets SoundId property
lightSound.Parent = script -- Sets the parent of the sound to the script
lightSound.RollOffMode = Enum.RollOffMode.Linear -- Set the roll-off mode
lightSound.RollOffMaxDistance = 5 -- Set the maximum distance the sound can be heard

-- Generator Sound
local generatorSound = Instance.new("Sound") -- Creates a new Sound instance
generatorSound.SoundId = workspace.Lamp.generator.Sound.SoundId -- Sets SoundId property
generatorSound.Parent = script -- Sets the parent of the sound to the script
generatorSound.RollOffMode = Enum.RollOffMode.Linear -- Set the roll-off mode
generatorSound.RollOffMaxDistance = 10 -- Set the maximum distance the sound can be heard
generatorSound.Volume = .05

-- Light Data
light.Brightness = 1.75
light.Color = Color3.new(255, 243, 196)
light.Range = 21

-- Event
prompt.Triggered:Connect(function()
	print("Prompt triggered") -- Debugging: Check if the prompt is triggered
	if not light.Enabled then
		-- Turn on light
		lamp.Transparency = 0
		lamp.Color = Color3.fromRGB(255, 151, 142)
		light.Enabled = true

		-- Play light sound
		lightSound:Play()
		lightSound.Looped = true

		-- Play generator sound
		generatorSound:Play()
		generatorSound.Looped = true

		-- Add light animation here if desired
	else
		-- Turn off light
		lamp.Transparency = 0.75
		lamp.Color = Color3.fromRGB(100, 100, 100)
		light.Enabled = false

		-- Stop light sound
		lightSound.Looped = false
		lightSound:Stop()

		-- Stop generator sound
		generatorSound.Looped = false
		generatorSound:Stop()
	end
end)

•▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬•

Let me know if I have missed something and feel free to link any external links in assistance to solving the issue.

Sounds need to be parented to a Part or Attachment to be spatial.
Also, why not just put the sounds into each Part (don’t use all the script nonsense) and just Play() or Stop() the sound when the ProximetyPrompt is fired. You can manually set all the Properties of the sound (Looped, RollOffMin and Max Distances, Volume etc.)
Easy peasy.

1 Like

I’m a programmer, not a scripter. It’s just by nature that I automate everything, and also just because it is easier and faster to do everything through a script for me rather than to go between the explorer and script to change small things. Additionally, it makes it easier to see what settings are essential in the script.

I have changed some things in the code. The sounds’ parents are now the parts the sound should be coming from.

-- Sounds
-- Light Sound
local lightSound = Instance.new("Sound") -- Creates a new Sound instance
lightSound.SoundId = workspace.Lamp.Base.light.Sound.SoundId -- Sets SoundId property
lightSound.Parent = workspace.Lamp.Base.light -- Sets the parent of the sound to the script
lightSound.RollOffMode = Enum.RollOffMode.InverseTapered -- Set the roll-off mode
lightSound.RollOffMaxDistance = 30 -- Set the maximum distance the sound can be heard

-- Generator Sound
local generatorSound = Instance.new("Sound") -- Creates a new Sound instance
generatorSound.SoundId = workspace.Lamp.generator.Sound.SoundId -- Sets SoundId property
generatorSound.Parent = workspace.Lamp.generator -- Sets the parent of the sound to the script
generatorSound.RollOffMode = Enum.RollOffMode.InverseTapered -- Set the roll-off mode
generatorSound.RollOffMaxDistance = 50 -- Set the maximum distance the sound can be heard
generatorSound.Volume = .05

Your solution was a success.

1 Like

Yes, I’m a builder first and learning my way into scripting now.
I find it much easier to preset all the parameters of items in Studio, then I only have to code for parameters I wish to change in the script.

I sometimes get overwhelmed with code. When I see code with all the extra paramters ‘clogging’ up the script (like the 12 lines of code setting all the parameters) and causing me to have to scroll through more lines when less would work it’s much easier.

Also in this case I just make my Lights Neon and change the Material, or the Transparency to get rid of the neon glow. I leave the colour alone. It works pretty well.

I could maybe work something out wit h the color being left alone, but the other properties are essential to be changed conditionally to the script. I do write clean code, so it is not much of a problem for me.

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