I have this code below I use within a brick in my shop. So when someone comes in the shop the music starts to play because the brick has been touched. The brick is invisible.
I also have another brick outside the door so when it is touched the music stops which it works. But I don't know how to make the music only be heard by the player not all players when touched.
This is the code for onTouched brick in the shop to start playing the music which works.
function onTouched(hit) script.Parent.Parent.Shopsound:play() script.Parent.Shopsound.Pitch = 0.5 script.Parent.Shopsound.Volume = 0.5 end script.Parent.Touched:connect(onTouched)
This is the code for onTouched brick outside the shop door to stop playing the music when they walk out which works.
function onTouched(hit) script.Parent.Parent.Shopsound:stop() end script.Parent.Touched:connect(onTouched)
No matter what if a sound is played in the workspace then anyone can hear it. Make a sound local by having it client-side, like simply inside the player object.