Empty
Empty
Empty
SoundService is a service in Roblox that handles the playback of sounds in your game. It allows you to manage global sound settings and playback for background music, announcements, and other sounds that should be heard by all players regardless of their location in the game world.
Background Music with Looping
Roblox Studio
Play Sound from Script
Empty
Empty
Empty
- Server Script: If a server-side script plays a sound that is parented to a part in the workspace, it will generally be heard by all players who are near that part.
- Local Script: If a client-side script plays a sound, only the player running the script will hear it.
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)
If you found this tutorial helpful and would like to support my work, please consider buying me a coffee.
Thank you very much for your support!
Buy me a coffee