How To Set A Timout On A Function

I don’t know why, but @ExcessEnergy deleated his original post, which helped me solve my problem. What I did was something like this:

    local timeout = 3
    local timeoutEnded = false
    spawn(function()
    wait(timeout)
    timeoutEnded = true
    end)
    while timeoutEnded == false do
    --run function stuff here
    end

@kylerzong’s may also work, but I haven’t tested it. (Also happy birthday, kylerzong! At the time i’m writing this it says it is your birthday)
Thanks Everyone!