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 8 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.


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

Log in to vote
0
Answered by 8 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.

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.

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 — 8y
Ad

Answer this question