BindToClose help

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)

You never declared a variabled named externaldb in your code, that’s why it can’t send stuff.

Also if externaldb is supposed to be HttpService, then I need to inform you that HttpService doesn’t have a function named SetAsync.

I’m not declaring in this code snapshot for a purpose as its linked to another module.

A friend gave the idea to use repeat wait() which somewhat worked. Thanks anyway tho.

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

I actually never knew that. Well for anyone who was interested in the final result