I’m trying to create a sound region where if the player goes into it disables the normal game’s ambient system and enables the ambient when the player comes out. The main problem with the script is that once you go into the sound region, it plays the designated sound but the ambient sound system enables after a second, I’m not sure of a way to make this work and any help would be greatly appreciated.
Directory LocalPlayer>PlayerGui>Main (LocalScript)
local player = game.Players.LocalPlayer
local soundRegions = workspace:WaitForChild("SoundRegions")
local SoundService = game:GetService("SoundService")
local Found = false
while wait(1) do
for i, v in pairs(soundRegions:GetChildren()) do
Found = false
local region = Region3.new(v.Position - (v.Size/2),v.Position + (v.Size/2))
local parts = game.Workspace:FindPartsInRegion3WithWhiteList(region, player.Character:GetDescendants())
for _, parts in pairs(parts) do
if parts:FindFirstAncestor(player.Name) then
Found = true
break
else
Found = false
end
end
--main issue is below
if Found == true then
if script.Parent.SoundRegions[v.Name].IsPlaying == false then
script.Parent.SoundRegions[v.Name]:Play()
SoundService.AmbientSounds.Birds:Stop()
SoundService.AmbientSounds.Crickets:Stop()
break
end
else
script.Parent.SoundRegions[v.Name]:Stop()
if script.Parent.SoundRegions[v.Name].IsPlaying == false then
if SoundService.AmbientSounds.Birds.IsPlaying == false then
SoundService.AmbientSounds.Birds:Play()
SoundService.AmbientSounds.Crickets:Play()
break
end
end
end
end
end
Here are the sounds I’d like to play, they can play at the same time due to another script handling volume:
Thanks again for any help.