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

My random music selector is not working? [Resolved]

Asked by 9 years ago
lobbymusic = script:WaitForChild("lobbymusic")
print("Got table 'Lobbymusic!'")
local replicatedstorage = game:GetService("ReplicatedStorage")
print("Got replicatedstorage!")
local statustag = replicatedstorage:WaitForChild("statustag")
print("Got statustag!")
local electro = script.lobbymusic:WaitForChild("electro")
print("Got electro!")
local motivational = script:WaitForChild("motivational")
print("Got m1!")
local rogue = script:WaitForChild("rogue")
print("Got m2!")
local threestep = script:WaitForChild("threestep")
print ("Got threestep!")
local playing = script:WaitForChild("musicplaying")
print("Got boolean 'Playing!'")
lobbytable = lobbymusic:GetChildren()
print("Got children of table 'Lobbymusic!'")

while true do
    wait()
    if playing.Value == true then
        print("Music is already playing!")
    elseif playing.Value == false then
        if statustag.Value == "Error: Not enough players! Invite a friend to start playing!" or statustag.Value == "The game will start soon" and playing.Value == false then
            playmusic = lobbytable[math.random(1,#lobbytable)]:Play()
            for vol = 0,0.6,0.05 do
                wait(0.2)
                playmusic.Volume = vol
            end
        end
    end
end

This basically puts music into a table and then randomly plays one. For line 29 when I try to adjust its volume, however, it gives me this error: Line 29: Attempt to index global 'playmusic,' a nil value

0
Shouldn't you add a SoundId? woodengop 1134 — 9y
0
There is a sound ID. Even without a sound ID, it wouldn't return that error. dirty_catheter 7 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

You're setting the variable to the Play method of the sound, you need to set the variable to the sound without the Play method, put the Play method underneath and it should work.

lobbymusic = script:WaitForChild("lobbymusic")
print("Got table 'Lobbymusic!'")
local replicatedstorage = game:GetService("ReplicatedStorage")
print("Got replicatedstorage!")
local statustag = replicatedstorage:WaitForChild("statustag")
print("Got statustag!")
local electro = script.lobbymusic:WaitForChild("electro")
print("Got electro!")
local motivational = script:WaitForChild("motivational")
print("Got m1!")
local rogue = script:WaitForChild("rogue")
print("Got m2!")
local threestep = script:WaitForChild("threestep")
print ("Got threestep!")
local playing = script:WaitForChild("musicplaying")
print("Got boolean 'Playing!'")
lobbytable = lobbymusic:GetChildren()
print("Got children of table 'Lobbymusic!'")

while true do
    wait()
    if playing.Value == true then
        print("Music is already playing!")
    elseif playing.Value == false then
        if statustag.Value == "Error: Not enough players! Invite a friend to start playing!" or statustag.Value == "The game will start soon" and playing.Value == false then
            playmusic = lobbytable[math.random(1,#lobbytable)]
            playmusic:Play()
            for vol = 0,0.6,0.05 do
                wait(0.2)
                playmusic.Volume = vol
            end
        end
    end
end

0
Oh, right. Thanks! dirty_catheter 7 — 9y
0
No problem. :) Spongocardo 1991 — 9y
Ad

Answer this question