File size: 1,688 Bytes
0712d5f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | -- src/ServerScriptService/SoundscapeManager.server.lua
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SoundService = game:GetService("SoundService")
local SoundConfig = require(ReplicatedStorage:WaitForChild("Shared"):WaitForChild("SoundConfig"))
local SoundEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("SoundEvent")
-- Create ambient sound groups
local ambientGroup = Instance.new("SoundGroup")
ambientGroup.Name = "Ambient"
ambientGroup.Volume = SoundConfig.AmbientVolume
ambientGroup.Parent = SoundService
local sfxGroup = Instance.new("SoundGroup")
sfxGroup.Name = "SFX"
sfxGroup.Volume = SoundConfig.SFXVolume
sfxGroup.Parent = SoundService
-- Create ambient forest sound (looping)
local forestSound = Instance.new("Sound")
forestSound.Name = "ForestAmbient"
forestSound.SoundId = SoundConfig.ForestAmbient
forestSound.Looped = true
forestSound.Volume = 0.3
forestSound.SoundGroup = ambientGroup
forestSound.Parent = workspace
-- Start ambient
forestSound:Play()
-- Handle client SFX requests
SoundEvent.OnServerEvent:Connect(function(player, soundName, position)
-- Relay to all nearby clients
if SoundConfig[soundName] then
for _, otherPlayer in ipairs(game:GetService("Players"):GetPlayers()) do
if otherPlayer ~= player then
SoundEvent:FireClient(otherPlayer, soundName, position)
end
end
end
end)
-- Expose for server-side sound triggering
_G.PlayWorldSound = function(soundName, position)
for _, player in ipairs(game:GetService("Players"):GetPlayers()) do
SoundEvent:FireClient(player, soundName, position)
end
end
print("Soundscape Manager initialized")
|