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.
debounce = false script.Parent.Touched:connect(function(hit) if not debounce then debounce = true if(hit.Parent:FindFirstChild("Humanoid")~=nil)then while true do local player = game.Players:GetPlayerFromCharacter(hit.Parent) local sound = script.Parent.Sound:Clone() sound.Parent = player.PlayerGui sound:Play() wait(118.021) end debounce = false end end 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.
local debounce = false local soundID = "12345"--Replace this with your sound's ID script.Parent.Touched:connect(function(hit) if debounce==false then debounce = true if(hit.Parent:FindFirstChild("Humanoid")~=nil)then local player = game.Players:GetPlayerFromCharacter(hit.Parent) local sound = player.PlayerGui.Sound sound.SoundId = soundID sound:Play() wait(1) debounce = false end end end)
You didn't need the loop, by the way.