I am asking this b/c I've tried but many times it is very glitchy and hard to do. Is there a reliable way? I'm not asking for you to script it for me but to point me in the right direction & give me resources where I can find more information & give me advice, please.
You could mute the volume of the sound, by using SoundName.Volume = 0
, or, if you want it to fade out, you could use a For Loop
, like so:
game.Workspace.Sound:Play() --The location of the sound wait(10) -- Just an example, this could connect to a GUI button or anything else for i = 0, 1, 0.1 do game.Workspace.Sound.Volume = i --This is assuming your volume is set to 1 already, wait(0.1) --the speed of the fade, this could be anything --you could multiply the 0.1 and the iterator to end --use different volumes
If you would want to fade it back in, you could do the opposite, as such:
game.Workspace.Sound:Play() --The location of the sound wait(10) -- Just an example, this could connect to a GUI button or anything else for i = 1, 10 do game.Workspace.Sound.Volume = game.Workspace.Sound.Volume + 0.1 --This is assuming your volume is set to 1 already, wait(0.1) --the speed of the fade, this could be anything --you could multiply the 0.1 and the iterator to end --use different volumes
Hopefully I addressed your problem correctly!
I am guessing you want to know how to stop when your sound has reached a certain point. A way to do this, is to check the sound for the TimePosition value, which shows the progress of the sound in seconds. If you want to stop the sound when it has played for 5 seconds you would do this:
sound = script.Sound --Please select your sound if you copy this script while sound:Play() do --plays the sound if sound.TimePosition >= 5 then --Checks for when the sound has reached a certain point or further (because the timePosition value isn't very accurate) sound:Stop() --Stops the sound if it has reached 5 seconds end end