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

This sound will not fade out, why?

Asked by
Oullim 0
8 years ago

I don't understand why it doesn't work

s = game.Workspace.KeepGrouped.Sound -- Where sound is located. Don't change unless you know what you are doing.
s:Play() -- Plays the sound
function onKeyPress(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then
        s.Volume=0.9 -- Volume after waited for time in brackets 
        wait (.3) -- Time before volume change
        s.Volume=0.8 -- Volume after waited for time in brackets
        wait (.2) -- Time before volume change
        s.Volume=0.7 -- Volume after waited for time in brackets
        wait (.3) -- Time before volume change
        s.Volume=0.6 -- Volume after waited for time in brackets
        wait (.2) -- Time before volume change
        s.Volume=0.5 -- Volume after waited for time in brackets
        wait (.2) -- Time before volume change
        s.Volume=0.4 -- Volume after waited for time in brackets
        wait (.3) -- Time before volume change
        s.Volume=0.3 -- Volume after waited for time in brackets
        wait (.2) -- Time before volume change
        s.Volume=0.2 -- Volume after waited for time in brackets
        wait (.3) -- Time before volume change
        s.Volume=0.1 -- Volume after waited for time in brackets
        wait (.2) -- Time before volume change
        s.Volume=0 -- Sound is silent
        s:Stop() -- Stops music
    end
end

game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.E)
0
Remove the parameters of your onKeyPress function, and the if statement. The function will only run if the player presses E, so the if statement is not needed. TheDeadlyPanther 2460 — 8y
0
@Above But I want it to stop when i press E Oullim 0 — 8y
0
Is there any output? Also, if this is a localscript, then you might want to address the mouse and use the KeyDown event instead of the ContextActionService lightpower26 399 — 8y
1
@lightpower No! KeyDown is deprecated! ContextActionService and UserInputService are the only things people should be using Validark 1580 — 8y
0
Try removing the space between the bracket and wait so like this : wait() instead of wait (), also I reccomend using a for loop instead of manually changing it again and again, hope this helped! LifeInDevelopment 364 — 8y

Answer this question