|
| 13 Jul 2014 08:13 AM |
I'm becoming a regular here with these audio problems...
To keep this short and sweet, I have a looped sound play from the StarterGui when a player hits a part. Since this sound is looped, it never goes off but is so short that it needs to be looped a few times.
So, I need a part for a player to touch that will stop the loop. Here is the current script that plays the loop.
debounce = false
script.Parent.Touched:connect(function(hit) if not debounce then debounce = true if(hit.Parent:FindFirstChild("Humanoid")~=nil)then local player = game.Players:GetPlayerFromCharacter(hit.Parent) local sound = script.Parent.Sound:Clone() sound.Parent = player.PlayerGui sound:Play() wait(30) end debounce = false end end)
I'm also looking for a fade out effect by lowering the volume by one until its zero if possible. Since this was made for me and my scripting knowledge is nil, I don't know where to begin however changing this to stop sound rather than play it I would imagine is a quick fix. Fading out I would imagine needs an if loop of some kind.
If anyone can help me with this it would be much appreciated, thanks for your time. |
|
|
| Report Abuse |
|
|
|
| 13 Jul 2014 09:03 AM |
To fade out you can use a for loop, for example:
for i = 0,1,0.1 do sound.Volume = i wait() end |
|
|
| Report Abuse |
|
|
|
| 13 Jul 2014 10:14 AM |
@above Thanks for the loop, much appreciated.
With the other problem, would it be a simple alteration like I thought to stop the sound from playing? Or will I need to create a brand new piece of code?
Also, where exactly would I put the loop? I assume it would need to go somewhere specific? |
|
|
| Report Abuse |
|
|
| |
|
| |
|
4567777
|
  |
| Joined: 13 Jul 2013 |
| Total Posts: 128 |
|
|
| 13 Jul 2014 01:12 PM |
debounce = false
script.Parent.Touched:connect(function(hit) if not debounce then debounce = true if(hit.Parent:FindFirstChild("Humanoid")~=nil)then local player = game.Players:GetPlayerFromCharacter(hit.Parent) local sound = script.Parent.Sound:Clone() sound.Parent = player.PlayerGui sound:Play() Spawn(function()--creates new thread so wait(30) wont be interrupted wait(3) -- waits 3 seconds, change this to how long you want it to loop for i = sound.Volume,0,-0.025 do -- loop until 0, removing 0.025 every time sound.Volume = i -- sets sound volume to i wait() end-- end fade out sound:Stop() -- stops sound after faded end) wait(30) end debounce = false end end) |
|
|
| Report Abuse |
|
|
|
| 13 Jul 2014 01:14 PM |
| I didn't look at your code but I have encountered problems with sounds in studio that were not problems when testing online. |
|
|
| Report Abuse |
|
|
|
| 13 Jul 2014 01:34 PM |
Thank you 4567777, this isn't the first time you've helped me.
Your code works however does something different to what I'm trying. Your code both activates and fades out the sound, however I need a script that when the part is touched, fades out a sound that is already playing. |
|
|
| Report Abuse |
|
|
| |
|
|
| 19 Jul 2014 05:18 AM |
You should use something like this:
Part.Touched:connect(function() -- fade out as I showed earlier Sound:Stop() end) |
|
|
| Report Abuse |
|
|