Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why wont this game:BindToClose(function() script not work!!??

You probably have seen something like this before, essentially i'm trying to kick the players before the server shuts down. The problem is it doesnt kick the player, and it prints "???" when it should kick me BEFORE printing that. Anyone have any ideas why this wont work???

game:BindToClose(function()
	for i, player in ipairs(game.Players:GetChildren()) do
		player:Kick("The Game Is Shutting Down, Please Rejoin")
	end
	print("???")
	wait(5)
end)

3 comments

0

Just a side note you should be using GetPlayers and not GetChildren. However the BindToClose method is called when the server shuts down, usually when the last player in a server leaves, maybe that's why it didn't kick.

0

it prints "???" and then waits 5 seconds before the server shuts down though

0

Can you suggest an alternative script because its clear this one doesn't work

1 answer

Note that you can only use this once in the game. Also, try this instead:

game:BindToClose(function()
for _,v in pairs(game:GetService("Players"):GetPlayers()) do
v:Kick("Game is shutting down...")
end
end)

1 comment

0

Nope, just says Developer Has shut down servers...

This discussion is preserved as it was. New answers, comments, and votes are closed.