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

math.random sound picker causing counter to not count down?

Asked by 7 years ago
Edited 7 years ago

So I read the roblox wiki on how to use math.random to make a random something picker, so I read it, and added it to these scripts;
Script in ServerScriptService

seconds = game.Workspace.serverstuff.seconds
game.Workspace.serverstuff.roundover.Value = true
roundover = game.Workspace.serverstuff.roundover
currentsong = game.Workspace.serverstuff.currentsong 

function playRandomSong()
    local songlist = game.ServerStorage.songs:GetChildren()
    randomsong = math.random(1,#songlist)
    randomsong:Play()
    currentsong.Value = randomsong.Name 
end

function stopRandomSong()
    randomsong:Stop()
end

while true do
if roundover.Value == true and game.Players.NumPlayers >= 4 then    
    seconds.Value = 30  
    playRandomSong()        
    repeat 
    wait(0.5)   
    seconds.Value = seconds.Value - 1
    wait(0.5)
until
    seconds.Value == 0
    stopRandomSong()
    currentsong.Value = ""
end

roundover.Value = false

wait(5)

roundover.Value = true
end

LocalScript in StarterPack

--Define stuff
player = game.Players.LocalPlayer
player.PlayerGui:WaitForChild("ScreenGui")
timegui = player.PlayerGui.ScreenGui.TextLabel
seconds = game.Workspace.serverstuff.seconds
roundover = game.Workspace.serverstuff.roundover
currentsong = player.PlayerGui.songgui.TextLabel
songvalue = game.Workspace.serverstuff.currentsong

while wait() do
    if roundover.Value == true and game.Players.NumPlayers >= 4 then
        timegui.Text = "Next game starts in ".. seconds.Value .." seconds!"
            currentsong.Text = "Current Song : ".. songvalue.Value
            repeat 
            timegui.Text = "Next game starts in ".. seconds.Value .." seconds!"
            wait(1)
        until seconds.Value == 0
        currentsong.Text = "Current Song : No song playing!"
        timegui.Text = "Next game starts in ".. seconds.Value .." seconds!"
        wait(5)
    elseif game.Players.NumPlayers <= 4 then
        timegui.Text = "Not enough players!"
    end

end 

Here's the error in the output : ServerScriptService.Script:10: attempt to index global 'randomsong' (a number value) And now the counter doesn't count down and the sound doesn't play, where did I skrub up these scripts?

Answer this question