SoundService

SoundService è un servizio in Roblox che gestisce la riproduzione dei suoni nel tuo gioco. Ti consente di gestire le impostazioni sonore globali e la riproduzione di musica di sottofondo, annunci e altri suoni che dovrebbero essere ascoltati da tutti i giocatori indipendentemente dalla loro posizione nel mondo di gioco.

Musica di Sottofondo con Ripetizione

Image 1
Roblox Studio

Riproduci Suono da Script

  • Script del Server: Se uno script lato server riproduce un suono che è associato a una parte nel workspace, sarà generalmente udibile da tutti i giocatori vicini a quella parte.
  • Script Locale: Se uno script lato client riproduce un suono, solo il giocatore che esegue lo script lo sentirà.
-- 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)

Se hai trovato utile questo tutorial e desideri supportare il mio lavoro, considera di offrirmi un caffè.

Grazie mille per il tuo supporto!

Offrimi un caffè