Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can someone help me with a sound script?

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)

1 answer

✓ Accepted answer

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.

1 comment

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.