Heya!
Throughout my game development, I have built a lobby that acts like a resort and I am working on enhancing its environment details. One of those details being is audio. I have an audio playing in the player’s PlayerGui where it just plays ocean noises.
When entering in and out of the main building, the ocean audio remains at the same volume level. Obviously I don’t want this, I want to create the perspective of actually being inside a building.
I have built barriers inside the building and named the group appropriately while using the :GetPartsObscuringTarget(). So whenever the camera is inside the barriers, it the following would lower the volume level.
Barriers selected in the image:
I attempted this as a water ambient script in one of my previous projects and it worked successfully. However, it doesn’t seem to be working too well here.
LocalScript in StarterGui:
local group = workspace.AudioModifier_Group -- group of barriers
local audio = script.Parent.sea --audio
while true do
wait(0.025)
local castPoints = {
group.BarrierOne.Position;
group.BarrierTwo.Position;
group.BarrierThree.Position;
group.BarrierFour.Position;
}
local ignoreList = {}
local parts = workspace.CurrentCamera:GetPartsObscuringTarget(castPoints,ignoreList)
local inLobby = false
if #parts > 0 then
for _, c in pairs(parts) do
if c.Name == "BarrierOne" or "BarrierTwo" or "BarrierThree" or "BarrierFour" then
inLobby = true
break
end
end
end
if inLobby then
audio.Volume = 0.015
else
audio.Volume = 0.2 --Volume is normally 0.2 when outside
end
end
Upon joining the server, I am greeted with constant fluctuated volume of the ocean audio no matter where my camera is pointing at. It keeps bouncing from the audio points 0.2 and 0.015, which is very jarring.
How can I counter this?