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

Broken audio selection script / Not playing requested sound ID?

Asked by 6 years ago

to give you a sense of what im triyng to do -- once you press play - the audio goes down and it's soundid is set to blank, once you press a music selection, it loads up the soundid and plays it-- however it is now working correctly-

The audio enabled script

function Click()
script.Parent.BackgroundTransparency = 0.5
wait(0.01)
script.Parent.BackgroundTransparency = 1
game.Workspace.Sound.Volume = 0
wait(0.4)
game.Workspace.Sound.Volume = 0.1
wait(0.4)
game.Workspace.Sound.Volume = 0.2
wait(0.4) 
game.Workspace.Sound.Volume = 0.3
wait(0.4) 
game.Workspace.Sound.Volume = 0.4
wait(0.4) 
game.Workspace.Sound.Volume = 0.5
wait(0.4) 
game.Workspace.Sound.Volume = 0.6
wait(0.4) 
game.Workspace.Sound.Volume = 0.7
wait(0.4) 
game.Workspace.Sound.Volume = 0.8
wait(0.4) 
game.Workspace.Sound.Volume = 0.9
wait(0.4) 
game.Workspace.Sound.Volume = 4
wait(0.4)
game.Workspace.Sound:Play()
wait(0.4) 
end

script.Parent.MouseButton1Down:connect(Click)

Selection button -


function Click() script.Parent.BackgroundTransparency = 0.5 wait(0.01) script.Parent.BackgroundTransparency = 1 game.Workspace.Sound.Volume = 4 game.Workspace.Sound.SoundId = "158762696" game.Workspace.Sound:Play() end script.Parent.MouseButton1Down:connect(Click)

Output : Sound Workspace.Sound Failed to load 27697743

1 answer

Log in to vote
1
Answered by
Mayk728 855 Moderation Voter
6 years ago
Edited 6 years ago

The issue is that you're supposed to add "rbxassetid://" before the ID. Yes, on studio it adds the link automatically, but in a script, you manually have to add the link before the ID. Also, there's a more efficient way of making the volume fade up. You could also put the two scripts together rather than having two separately.

script.Parent.MouseButton1Down:Connect(function()
    spawn(function() --This allows the inner code to run at the same time as the outer code.
        script.Parent.BackgroundTransparency = 0.5
        wait(0.01)
        script.Parent.BackgroundTransparency = 1
        for i = 0,4,.1 do
            workspace.Sound.Volume = i
            wait()
        end
    end)

    script.Parent.BackgroundTransparency = 0.5
    wait(0.01)
    script.Parent.BackgroundTransparency = 1
    workspace.Sound.Volume = 4
    workspace.Sound.SoundId = "rbxassetid://158762696"
    workspace.Sound:Play()
end)

Here's an explanation of the for loop.

for i = 0, 4, 0.1 do

0 is the starting point, 4 is the ending point, and 0.1 is the amount it goes up. It keeps looping until it reaches the ending point, which is 4. If you wanted it to fade out, just make it -0.1 instead.

0
Thanks. I really appreciate it! Deploy_Coffee 7 — 6y
0
Could you accept their answer? It's the best way to show appreciation and let others know that it's the right answer. :) User#18718 0 — 6y
Ad

Answer this question