How do I Kick players Globally

I thought it would be a great idea to make an advanced kick system by making it global kick
I think the best way to do is to use MessagingService

But i couldnt test it since roblox was down. Give me ways that works

MessagingService is fine, but make sure to handle for the rare chance any subscribing server did not receive the publish if that is reliability is important.

1 Like

Similar to what @DrKittyWaffles said,

MessagingService will be needed, when the command is ran, publish with the player you want to kicks UserId, then when you subscribe, loop through GetPlayers() and see if their UserId matches, then you can finally do Player:Kick()

edit: GetUserIdFromNameAsync() is a great tool for this situation, but you could always just also send the player name

Alright, like you said, MessagingService would be the best way to do this.
Something like this should work,

local MessagingService = game:GetService("MessagingService")
local Username = "faresalqrni143"

function kick(user)
	MessagingService:PublishAsync("PlayerKick", user)
end

MessagingService:SubscribeAsync("PlayerKick", function(data)
	local user = data.Data
	local player = game.Players:FindFirstChild(user)
	
	if player then
		player:Kick()
	end
end)

wait(5)

kick(Username)

If I remember correctly, MessagingService doesn’t work in studio, so you’ll have to publish and test.


If you wanted to be able to add a Kick Message, you could do something like this,
local MessagingService = game:GetService("MessagingService")
local Username = "faresalqrni143"

function kick(user, reason)
	MessagingService:PublishAsync("PlayerKick", {Username = user, Reason = reason})
end

MessagingService:SubscribeAsync("PlayerKick", function(data)
	local data = data.Data
	
	local user = data.Username
	local reason = data.Reason
	local player = game.Players:FindFirstChild(user)
	
	if player then
		player:Kick(reason)
	end
end)

wait(5)

kick(Username, "test")
1 Like

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