So I wanna play a sound locally when the client touches a part. I have read the PlayLocalSound() article on the dev forum but didnt understand much, could someone give me an example code?
COMMUNITY QUESTION
How can I play a sound locally?
1 answer
There's a script sample already created for this. Here it is:
local trigger = game.Workspace.klaxontrigger
local isplaying = false
local SoundService = game:GetService("SoundService")
local plr = game.Players.LocalPlayer
local function playLocalSound(soundId)
if isplaying then
return
end
isplaying = true
local sound = SoundService.klaxonbeat
SoundService:PlayLocalSound(sound)
sound.Ended:Wait()
isplaying = false
end
local function onTouch(part)
if part.Parent.Name == plr.Name then
playLocalSound(190619411)
end
end
trigger.Touched:Connect(onTouch)
https://devforum.roblox.com/t/playlocalsound-plays-to-everyone-in-the-server/598207/2
This discussion is preserved as it was. New answers, comments, and votes are closed.
