I have a yielding function in a script inside ServerScriptService that I need to make sure fully runs even after the last player has left. I already looked in the forums for an answer but I didn’t find anything.
1 Like
have you tried game:bindtoclose
I looked at it in the docs and from what I understood it would call the function. I don’t want it to call the function, I simply want to make sure it has finished running before the server shuts down
you could probably use a Boolean flag for this.
local isSafeToClose = true --global, at the top of your script
local function thisMustFinish()
isSafeToClose = false
--logic
isSafeToClose = true
end
--then
game:BindToClose(function()
repeat task.wait() until isSafeToClose
end)
note that BindToClose can only run for a maximum of 30 seconds… so you basically have a 30s time limit after the game is set to close
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.