Confused with script

Hiya developers!

I would like to ask for some help with this script.

I keep getting a bug. There are no errors in the output, so I’m confused to why the bug is happening.

The bug is that my script runs over and over again (Which I want), until it suddenly just stops. no errors, nothing.

Here is my code if you are able to help me:

Thank you so much for your help.

1 Like

throw in some prints to help with debugging. usually using while(true) you can get some funky stuff to happen. maybe try using runservice

2 Likes

why are you creating a local function inside of a loop

1 Like

You are creating the local function inside a while true do loop, and anything outside that loop will not be able to access that function. You will not be able to call the runGame function, but attempting to call it will not throw any error. It will just do nothing.

Here’s a corrected version of your code:

local function runGame() -- notice how this is not inside any while true do loops?
    -- contents of your function
end

while true do
    local Success, Error = pcall(runGame)
    if not Success then
        warn("An error has occured in the intermission loop: " .. Error)
        task.wait(5) -- A better and more accurate alternative to wait()
    end
    task.wait(60)
end

you can also get rid of the while true do replace it with while task.wait(60) do instead