I’m using bindtoclose to save chat logs onto an external server, yet its failing to send before the server closes. Any suggestions in order to delay the closing time?
local Logs = {}
local HttpService = game:GetService("HttpService")
game.Players.PlayerAdded:Connect(function(plr)
local key = tostring(plr.UserId)
Logs[key] = {}
plr.Chatted:Connect(function(message)
local chatTable = {
['Sender'] = plr.Name,
['Time'] = tostring(os.time()),
['Message'] = message
}
table.insert(Logs[key], chatTable)
end)
end)
game:BindToClose(function()
local logs = HttpService:JSONEncode(Logs)
pcall(function()
externaldb:SetAsync(tostring(game.JobId),logs)
end)
end)
Actually BindToClose delays the server from closing until all bound functions have finished. The game will wait a maximum of 30 seconds for all bound functions to complete running before shutting down.
Based on that it may be that your function is failing somewhere