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

player:Kick() not working in BindToClose() function?

Inside my BindToClose() function, I have this:

game:BindToClose(function()
	print("BindToClose Function For Leaderboard Runs Now!")
	
	if not RunService:IsStudio() then
		print("Player not detected in studio")
		for _, player in pairs(game.Players:GetPlayers()) do -- notice that you can loop through every player left in the server so the function can run for them
			print(player)
			player:Kick("Server is shutting down. Please rejoin, your game data will be saved.") -- WHY DOESN'T THE PLAYER GET KICKED. I DON'T SEE THIS MESSAGE.
			print("Message sent to player for being kicked!")
		end
		while true do
			wait()
		end
	else
		wait(5)
	end
end)

And this is the script for the skips:

game:BindToClose(function()
	print("BindToClose Function For Skips Runs Now!")

	if not RunService:IsStudio() then
		print("Player not detected in studio")
		for _, player in pairs(game.Players:GetPlayers()) do -- notice that you can loop through every player left in the server so the function can run for them
			print(player)
			player:Kick("Server is shutting down. Please rejoin, your game data will be saved.") -- WHY DOESN'T THE PLAYER GET KICKED. I DON'T SEE THIS MESSAGE.
			print("Message sent to player for being kicked!")
		end
		while true do
			wait()
		end
	else
		wait(5)
	end
end)

Why don't the player's get kicked? I tested this is roblox server and the console prints the player but not the actual kicking part.

1 answer

The problem with BindToClose is that you cannot use :Kick() when this function is fired. This is because, this function fires when the server shuts down (it just delays the server shutdown up to 30 seconds). So, using :Kick() is useless.

The dev says : Bound functions will be called in parallel, meaning they will run at the same time.

So, if you add another line after plr:Kick(), it will execute.

I know it's hard to understand, but you can't kick the player using BindToClose.

2 comments

0

Is there any way to change the delay of server shutdown for maybe just 5 seconds? If not, then is there any way to kick the player when the server shutdowns (not in the delay time). As soon as we click on shutdown all servers?

0

Well, the problem is when you click on server shutdown, the server shutdowns immediately and due to BindToClose, it can be delayed for the maximum of 30 seconds. The problem, here, is all the client scripts stop working on server shutdown and it becomes nearly impossible to kick players.

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