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

Can someone help me with a sound script?

Asked by 9 years ago

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.

01debounce = false
02 
03script.Parent.Touched:connect(function(hit)
04if not debounce then
05debounce = true
06if(hit.Parent:FindFirstChild("Humanoid")~=nil)then
07while true do
08local player = game.Players:GetPlayerFromCharacter(hit.Parent)
09local sound = script.Parent.Sound:Clone()
10sound.Parent = player.PlayerGui
11sound:Play()
12wait(118.021)
13end
14debounce = false
15end
16end
17end)

1 answer

Log in to vote
0
Answered by 9 years ago

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.

01local debounce = false
02local soundID = "12345"--Replace this with your sound's ID
03 
04script.Parent.Touched:connect(function(hit)
05if debounce==false then
06debounce = true
07if(hit.Parent:FindFirstChild("Humanoid")~=nil)then
08local player = game.Players:GetPlayerFromCharacter(hit.Parent)
09local sound = player.PlayerGui.Sound
10sound.SoundId = soundID
11sound:Play()
12wait(1)
13debounce = false
14end
15end
16end)

You didn't need the loop, by the way.

0
Thank you so much. I didn't think i would get a response so fast, looks like ill be using this site more often. Galvarino 25 — 9y
Ad

Answer this question