File size: 1,026 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 | -- src/StarterPlayer/StarterCharacterScripts/SoundController.client.lua
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SoundConfig = require(ReplicatedStorage:WaitForChild("Shared"):WaitForChild("SoundConfig"))
local SoundEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("SoundEvent")
local function playSound(soundName, position)
local soundId = SoundConfig[soundName]
if not soundId then return end
local sound = Instance.new("Sound")
sound.SoundId = soundId
sound.Volume = SoundConfig.SFXVolume or 1
sound.RollOffMaxDistance = 100
if position then
local att = Instance.new("Attachment")
att.WorldPosition = position
att.Parent = workspace.Terrain
sound.Parent = att
sound:Play()
sound.Ended:Once(function() att:Destroy() end)
else
sound.Parent = workspace
sound:Play()
sound.Ended:Once(function() sound:Destroy() end)
end
end
SoundEvent.OnClientEvent:Connect(function(soundName, position)
playSound(soundName, position)
end)
|