Empty
Empty
Empty
SoundServiceは、Robloxでゲーム内の音声再生を処理するサービスです。グローバルなサウンド設定を管理し、背景音楽、アナウンス、その他の音声をゲーム内のすべてのプレイヤーに聞こえるようにします。
ループする背景音楽
Roblox Studio
スクリプトから音を再生
Empty
Empty
Empty
- サーバースクリプト: サーバー側のスクリプトがWorkspace内のパーツに親子関係を持つ音声を再生する場合、そのパーツに近いすべてのプレイヤーに聞こえます。
- ローカルスクリプト: クライアント側のスクリプトが音声を再生する場合、そのスクリプトを実行しているプレイヤーだけがその音を聞くことができます。
Empty
Empty
Empty
-- 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)
Empty
Empty
Empty
-- 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)