I'm trying to make a script that changes music when you walk from one area to another. I have the script that plays music down, but i have no clue how to make it change. Here's the script for putting the sound in, so you can center your answer off of it.
01 | debounce = false |
02 |
03 | script.Parent.Touched:connect( function (hit) |
04 | if not debounce then |
05 | debounce = true |
06 | if (hit.Parent:FindFirstChild( "Humanoid" )~ = nil ) then |
07 | while true do |
08 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
09 | local sound = script.Parent.Sound:Clone() |
10 | sound.Parent = player.PlayerGui |
11 | sound:Play() |
12 | wait( 118.021 ) |
13 | end |
14 | debounce = false |
15 | end |
16 | end |
17 | end ) |
Rather than cloning the Sound
, you could have a Sound
object in player.PlayerGui
. Then each script could have their own SoundID
(the ID of the music that you want to play) that is copied to the Sound
object in the GUI.
01 | local debounce = false |
02 | local soundID = "12345" --Replace this with your sound's ID |
03 |
04 | script.Parent.Touched:connect( function (hit) |
05 | if debounce = = false then |
06 | debounce = true |
07 | if (hit.Parent:FindFirstChild( "Humanoid" )~ = nil ) then |
08 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
09 | local sound = player.PlayerGui.Sound |
10 | sound.SoundId = soundID |
11 | sound:Play() |
12 | wait( 1 ) |
13 | debounce = false |
14 | end |
15 | end |
16 | end ) |
You didn't need the loop, by the way.