just yesterday this was all working fine and running every time but now it just doesnt work now
what i have is a server creation system where servers are created on a press of a button. their data is stored within a datastore. then they are tped to that server. when the server closes (when everybody leaves) i use game:BindToClose() to run a clear data function.
function clearData() -- binded method
if owner.serverId == nil or owner.player == nil then
return
end
MessagingService:PublishAsync("ServerConnections", {
serverId = owner.serverId,
owner = owner.player.UserId,
close = true,
})
destroyServerData(owner.serverId)
end
function destroyServerData(id)
local data = ServerStore:GetAsync(id)
if data == nil then
return "not a server"
end
ServerStore:RemoveAsync(id)
end
(no owner.serverid and owner.player are not nil. i know that for sure)
(also data isnt nil either because after using the datastore editor i see it right there)
(ServerStore is a custom module i made to configure a datastore method im using)
i use messaging service to send back to the lobby server to remove the data it stores within its cache table (since i dont request to the datastore every frame, thats not smart) everything worked yesterday. but the day before it wasnt working and now today it is. so game:BindToClose() isnt running consistently. its very hard to debug this since i cant view the dev console after the server closes.
testing this in studio wont work either since i need the data from the lobby where i was teleported from. using webhooks to send to discord wont work either since it will take too long to send and roblox shuts down the server after 30 seconds no matter what and im pretty sure the bind to close function isnt even running
so what im asking is there any other method that can consistently clear data on server close. this needs to count for all the players leaving, the server shutting down, and a possible server crash. or am i just using game:BindToClose() incorrectly