Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

math.random song picker only picking 1 song everytime?

So, I'm trying to make a random song picker for intermission and it stays the same everytime. I even used

math.randomseed(tick())

And it still picks only one song so, whats wrong? Script in ServerScriptService

while true do
	math.randomseed(tick())	
	INTERMISSION_TIME = 45 --How long intermission is
	PLAY_TIME = 15 --How long people play for
	local songs = game.ServerStorage.Songs
	local songList = songs:GetChildren()	
	local randomSong = math.random(1, #songList)
	songs[randomSong]:Play()
	print(songs[randomSong].Name)
	wait(INTERMISSION_TIME)
	songs[randomSong]:Stop()
	wait(PLAY_TIME)
end

The songs are in serverstorage in a folder, each named 1,2,3 you get the idea. Each time it prints 3 and plays the third song.

1 answer

while true do
    math.randomseed(tick()) 
    INTERMISSION_TIME = 45 --How long intermission is
    PLAY_TIME = 15 --How long people play for
    local songs = game.ServerStorage.Songs
    local songList = songs:GetChildren()    
    local randomSong = math.random(1, #songList)
    songs[tostring(randomSong)]:Play()
    print(songs[randomSong].Name)
    wait(INTERMISSION_TIME)
    songs[randomSong]:Stop()
    wait(PLAY_TIME)
end

This discussion is preserved as it was. New answers, comments, and votes are closed.