Game:BindToClose

I am trying to make a script act so when a developer shuts down a server, every player gets kicked with a custom kick message.

It currently just delays the normal kick (The developer has shutdown the experience), it does not kick them with the custom message.

Here is my code:

game:BindToClose(function()
	for _,v in pairs(game.Players:GetChildren()) do
		v:Kick("The game has been shutdown due to updates!\nPlease rejoin!\n\n-TLA")
	end
	wait(99999999999999999999999999999999999999999999) -- I thought that this would stop the normal shutdown from happening.
end)

That’s because game:BindToClose() runs whenever the Server is closed - Meaning that all the Players have already been kicked by default, Which is probably why the Custom Kick Message is not showing up.

I would recommend you try using SoftShutdown2 to show a Message whenever the Servers go down for updates. (P.S: Adding a wait() after the Code won’t make the default Shutdown stop)

So how does soft shutdown work if the players are already kicked…?

SoftShutdown will basically teleport Players to a Temporary-Server. It’ll await until the update is (Probably) done and will Teleport the Players back.

Instead of trying to kick the player, maybe fire a remote to all clients which shows a UI telling the player to rejoin. After 30 seconds they’re kicked from the game as long as you have something yielding like a wait.

Also, you should be using task.wait() instead of wait(). Its the new version of wait() which is better in every way.

How is task.wait() better than wait()?

More reliable than wait() so yeah-

This is incorrect and SoftShutdown uses this functionality.

You’re right that it uses it. You can see it in the SoftShutdown2 code for yourself.


As for the actual issue here, I tested in studio and it seems like Player:Kick() is ignored once :BindToClose() fires. I agree that SoftShutdown would be better anyway since you won’t lose players after updating the game.

1 Like

It’s not “more reliable”, but task.wait doesn’t have the 29ms minimum wait time that wait does.

It runs on Heartbeat, which means its faster, and more accurate than wait().

from the task API reference: Unlike the global wait , this function does not throttle and guarantees the resumption of the thread on the first Heartbeat that occurs when it is due. Less throttling means more accurate.

I know, however soft shutdown always traps my players in private servers…

Well, there isn’t any other way now. Either choose soft shutdown or just use the default kick message.

I dont agree with that, but I will use softshutdown.