:Kick() not working

I was making a global shutdown function and for some reason the Kick line isn’t working…


local DataStoreModule = require(game:GetService("ServerScriptService").Modules.Datastore)

MessagingService:SubscribeAsync("GShutdown",function(message)
	game.ReplicatedStorage.ServerValues.Shutdown.Value = true
	for i, v in pairs(game.Players:GetChildren()) do
		DataStoreModule.Save(v)
		v:Kick("Server shutdown: "..message)
	end
end)

game.ReplicatedStorage.Events.GShutdown.Event:Connect(function(message)
	MessagingService:PublishAsync("GShutdown", message)
end)

The datastore module prints when it finishes saving and I debugged it with a print before the kick that also ran, the kick just doesn’t kick the player at all. Everything else works fine.

It seems like you’re trying to do :GetChildren(). However, we need to get the Player instance in order to kick the Player. Therefore, you will need to replace :GetChildren() with :GetPlayers().

It still goes through the datastore perfectly and then doesn’t kick the player.


local DataStoreModule = require(game:GetService("ServerScriptService").Modules.Datastore)

MessagingService:SubscribeAsync("GShutdown",function(message)
	game.ReplicatedStorage.ServerValues.Shutdown.Value = true
	for i, v in pairs(game.Players:GetPlayers()) do
		DataStoreModule.Save(v)
		v:Kick("Server shutdown: "..message)
	end
end)

game.ReplicatedStorage.Events.GShutdown.Event:Connect(function(message)
	MessagingService:PublishAsync("GShutdown", message)
end)

I found out the issue was concatenating the MessagingService “string” in the kick message, when MessagingService sends a table instead, the error wasn’t logging until I added a wait before it for some reason though.


local DataStoreModule = require(game:GetService("ServerScriptService").Modules.Datastore)

MessagingService:SubscribeAsync("GShutdown",function(message)
	game.ReplicatedStorage.ServerValues.Shutdown.Value = true
	for i, v in pairs(game.Players:GetPlayers()) do
		DataStoreModule.Save(v)
		v:Kick("Server shutdown: "..message.Data)
	end
end)

game.ReplicatedStorage.Events.GShutdown.Event:Connect(function(message)
	MessagingService:PublishAsync("GShutdown", message)
end)

seen in v:Kick("Server shutdown: "..message.Data)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.