server output-[07:55:52.398 - Use the new http api: yes 07:55:56.831 - Started network server on 192.168.1.177|53640 07:55:56.832 - Started network server on 127.0.0.1|53640 Loading Cutscene Editor... 07:55:57.163 - Successfully opened file - C:/Users/layfo/AppData/Local/Roblox/server.rbxl Cutscene Editor Loaded play play play play play play 07:56:06.141 - New connection from 127.0.0.1|51716
play play play play play play play play play play Player -1 added]
test mode [07:56:00.416 - Use the new http api: yes Loading Cutscene Editor... 07:56:06.028 - ! Joining game '' place 0 at localhost 07:56:06.033 - Connecting to localhost:53640 Cutscene Editor Loaded 07:56:10.628 - Connection accepted from 127.0.0.1|53640
07:56:11.582 - BlackFrame is not a valid member of ScreenGui 07:56:11.583 - Script 'LoadingScript', Line 508 - global fadeBackground 07:56:11.584 - Script 'LoadingScript', Line 576 07:56:11.585 - Stack End]
music = script:GetChildren() while true do wait(1) function RandMusic() for i,v in pairs(music) do math.randomseed(tick()*math.random()) local MusicRandom = music[math.random(1, #music)] if MusicRandom ~= nil then print'play' MusicRandom:Play() local x = MusicRandom.TimeLength wait(x) end end end RandMusic() end
There are two major flaws in this code. You are unnecessarily recreating the RandMusic
function every loop. That's fixed by simply moving it outside of the while
loop.
The inner for
loop is completely unnecessary. All it does it play 1 random song for each song in the list, which probably isn't desired:
music = script:GetChildren() function RandMusic() math.randomseed(tick()*math.random()) --This actually causes this code to be *less* random, as the generated is seeded too often. You only need to call this line *once*, so I suggest moving this outside of this function. local MusicRandom = music[math.random(1, #music)] if MusicRandom then print('play') MusicRandom:Play() wait(MusicRandom.TimeLength) end end while true do wait(1) RandMusic() end