Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to get music to play in only one area?/Stop music being played?

Asked by 5 years ago
Edited 5 years ago

I'm trying to get music to play inside a particular area when touched.

Say, I have a room and I want the music to only play inside of that room.

So far, I've managed to get a brick to play music when touched, and put it on the entry to the room and am using the following script:

local sound = Instance.new("Sound", Workspace)
    sound.Pitch = 1 
    sound.SoundId = "rbxassetid://IDHERE" 
    sound.Volume = 1
    sound.Looped = true

    script.Parent.Touched:connect(function()
            sound:play()
        end)

The problem that I am having, is that the music is playing whenever the block is "touched" meaning that even just standing on it causes it to just play barely a second of the song before restarting- which is the least annoying problem, since I have put it at the entry to the room and it can be heard inside the room as the full song instead. Since atm, I have a small 1 stud thin strip on entry to the room that causes the music to be played.

The problem I do have, is how to stop the music when another sound playing brick is touched.

Or how to code a switch that will stop all music when pressed? I'm really new to code, and I'm pretty much useless at it, so if anyone could help me that'd be really helpful :)

Edit: I'm thinking I could have the "main part" before the room set to stop music when walked on? So that when they enter the different rooms the music would play, but on leaving would stop.

0
Two questions: 1) Is the state of the music shared across all players, or is each player independently in control of what music they hear? 2) Does the music have to be in Stereo? (Music playing from a part in the world is mixed to mono). The solution is completely different for 3D mono sound source vs players hearing the original stereo mix (non-directional). EmilyBendsSpace 1025 — 5y
0
I'm honestly not 100% sure if it is or not, but I want the music to be independently heard, not heard by every player, so it would be local. And as for the second question, I don't know, I just want it to only play in that area, or have a way to stop it from playing whilst it continues to play. MissFeral 0 — 5y

1 answer

Log in to vote
0
Answered by
c0nc3rt 61
5 years ago

I think the sound.Looped = true caused the problem, you should remove it.

If you want the music stop when player not touch the part, here is the script:

local sound = Instance.new("Sound", Workspace)
    sound.Pitch = 1 
    sound.SoundId = "rbxassetid://IDHERE" 
    sound.Volume = 1

script.Parent.Touched:connect(function()
            sound:play()
        end)
script.Parent.TouchEnded:Connect(function()
    sound:Stop()
end)

That's all, hope i helped you :).

Ad

Answer this question