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

why does this script work in studio mode and replays many times in test/play mode ?

Asked by 9 years ago

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
0
The error is not in the script you have above. It is in LoadingScript on line 508 User#5423 17 — 9y
0
i dont have any other scripts in the game only 1 Layfonex 0 — 9y
0
kingdom; that's actually a CoreScript. It's not a "real" error. adark 5487 — 9y

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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
0
still plays all songs and keep replaying it in test/play mode Layfonex 0 — 9y
0
TimeLength may be 0, then. Is this a LocalScript? adark 5487 — 9y
0
no its a script Layfonex 0 — 9y
0
TimeLength is over 70 Layfonex 0 — 9y
Ad

Answer this question