✓ Accepted answer
I have made an incredibly complicated way to make it work, but it works, so here it goes;
1: Create the part that you want the music to be played in, and name it 'SoundPlayer'
2: Insert Sound and name it 'Sound'. Insert Script and name it 'Play'. Finally, insert BoolValue and name it 'Debounce'
3: After all of that, put this code in the Script:
brick = script.Parent
sound = brick.Sound
debounce = script.Parent:findFirstChild("Debounce")
brick.Touched:connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr and debounce.Value == false then
debounce.Value = true
local play = sound:Clone()
play.Parent = plr.PlayerGui
play:Play()
wait()
end
end)
4: Create another part, and name it 'SoundRemover'
5: Insert a Script into this part, and name it 'Remove'. Then put in this code:
area = script.Parent
debounce = game.Workspace.Soundplayer:findFirstChild("Debounce")
area.Touched:connect(function(hit)
local play = game.Players:GetPlayerFromCharacter(hit.Parent)
local music = play.PlayerGui:findFirstChild("Sound")
if debounce.Value == true and music.IsPlaying == true then
music:remove()
debounce.Value = false
else
end
end)
Finally, duplicate 'SoundRemover' if necessary, and place it all around 'SoundPlayer' to make sure if the player leaves from any angle, the script stops the music.
If you have any questions about it, PM me or reply to this answer :)