How to check when a server closes/dies

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I want my code to save the int values value like you see in this picture when the game closes. Not when the deveoloper shutdowns the server. I simply want it to save when all the players leave and the server dies
Char
2. What is the issue? Include screenshots / videos if possible!

My problem is that i havent been able to find a solution on how you could make something like it. I tried to use “BindToClose” as you can see in the pic below. But that didnt work

Any help would be higly appreciated. Because i have been looking for 7 hours now. And still cant find anything related to my question >.<!!

1 Like

use datastores datastore will save any data even when the server close

1 Like

Yes i know. Thats what i’m trying to do. I just need to know how i would check when all the players leaves. And the server dies i guess you could say

use BindToClose im not sure if this is correct im not familliar with daaastores so yeah

1 Like

I already said that i tried it but it didnt work?

Are you testing this on Studio Solo? Or are you starting a server and starting. BindToClose is finicky in Solo so it might not work correctly every time.

2 Likes

I’m testing it in game not studio

game.Players.PlayerRemoving:Connect(function()
if #game.Players:GetChildren == 1 then
--insert code
end
end)
1 Like

Oh it was that easy… I feel so dumb now Xd

1 Like

its alright it happens to the best of us whn u have a problem saying it in ur head twice or thrice will always help

1 Like