最简单的做法就是在循环中检查时间是否超过6秒,超过就结束。比如下面代码(自己在循环中加入你要执行的操作)
local start = os.time()while os.difftime(os.time(), start) < 6 do -- Your operation hereend