SoundService

SoundService는 Roblox에서 게임 내 소리 재생을 처리하는 서비스입니다. 이를 통해 글로벌 사운드 설정을 관리하고 배경 음악, 공지 사항 및 기타 소리를 재생할 수 있으며, 이는 게임 세계의 모든 플레이어가 들을 수 있습니다.

반복되는 배경 음악

Image 1
Roblox Studio

스크립트에서 소리 재생

  • 서버 스크립트: 서버 측 스크립트가 Workspace에 있는 파트에 연결된 소리를 재생하면, 그 파트 근처에 있는 모든 플레이어가 소리를 들을 수 있습니다.
  • 로컬 스크립트: 클라이언트 측 스크립트가 소리를 재생하면, 그 스크립트를 실행 중인 플레이어만 소리를 들을 수 있습니다.
-- Workspace > SoundPart > PlayStepSoundScript

local soundPart = script.Parent
local stepSound = soundPart:WaitForChild("StepSound")


local function onTouched(otherPart)
    local character = otherPart.Parent
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    if humanoid then
        stepSound:Play()
    end
end

soundPart.Touched:Connect(onTouched)
-- StarterPlayerScripts > LocalStepSoundScript

local player = game.Players.LocalPlayer
local soundPart = workspace:WaitForChild("SoundPart")
local stepSound = soundPart:WaitForChild("StepSound")

local function onTouched(otherPart)
    local character = otherPart.Parent
    if character == player.Character then
        local humanoid = character:FindFirstChildOfClass("Humanoid")
        if humanoid then
            stepSound:Play()
        end
    end
end

soundPart.Touched:Connect(onTouched)