SoundService

SoundService es un servicio en Roblox que maneja la reproducción de sonidos en tu juego. Te permite gestionar configuraciones de sonido globales y la reproducción de música de fondo, anuncios y otros sonidos que deberían ser escuchados por todos los jugadores, sin importar su ubicación en el mundo del juego.

Música de Fondo con Bucle

Image 1
Roblox Studio

Reproducir Sonido desde Script

  • Script del Servidor: Si un script del servidor reproduce un sonido que está asociado a una parte en el workspace, generalmente será escuchado por todos los jugadores cercanos a esa parte.
  • Script Local: Si un script del cliente reproduce un sonido, solo el jugador que ejecuta el script lo escuchará.
-- 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)

Si encuentras útil este tutorial y deseas apoyar mi trabajo, considera invitarme a un café.

¡Muchas gracias por tu apoyo!

Invítame a un café