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

Why does my music script stop and in output it says "Game script timeout"?

Asked by 4 years ago

At the first line it just say "Game script timeout" in output.

if not sound.IsPlaying then
    setSong()
    sound:Play()
end

I hope one of you guys can help me. - Toby

0
(There are more in it, for example the "setSong()" is a function in the script. It's just the first line it's stops at.) tobiO0310 58 — 4y
0
Can you explain clearly please nkminion 21 — 4y
0
Look down, I posted the full script. tobiO0310 58 — 4y

2 answers

Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

This is because while loops run very fast. In fact, all loops run at high speeds, and for that require a cooldown to prevent them from overloading the runtime. To solve your issue, write wait() next to do.

Ad
Log in to vote
0
Answered by 4 years ago

Here is the full script:

local sound = game.Workspace.Sound

local songs = {2870416424, 1837466718, 1838103223}

local Song = 1

sound.Looped = false

while true do
    function setSong()

        local song = songs[Song]

        print(Song)

        Song = Song + 1

        sound.SoundId = "rbxassetid://"..song

        print(Song)

        if Song == #songs then
            Song = 1
        end

    end

    if not sound.IsPlaying then -- Stops at this line.
        setSong()

        sound:Play()
    end
end

Answer this question