Why is this not kicking players?

I have created a kick script however it is failing to work.

Localscript:

local DisconnectEvent = game:GetService("ReplicatedStorage"):WaitForChild("Disconnect")

script.Parent.MouseButton1Click:Connect(function()
	local KickUser = script.Parent.Parent.Parent.PlrName.Text
	DisconnectEvent:FireServer(KickUser)
end)

Server script:

Instance.new("RemoteEvent").Parent = game.ReplicatedStorage
game.ReplicatedStorage.RemoteEvent.Name = "Disconnect"
script.Parent = game.ServerScriptService

local DiscEvent = game:GetService("ReplicatedStorage"):WaitForChild("Disconnect")


	

DiscEvent.OnServerEvent:Connect(function(KickUser)
	
	local PlayerKick = game.Players:FindFirstChild(KickUser)
	print(KickUser)
	if PlayerKick then
		print("Final")
PlayerKick:Kick("Administrative Kick: An administrator has removed you from the game")	
end
end)
1 Like

Err, your referencing a event that doesn’t exist yet.

local DisconnectEvent = game:GetService("ReplicatedStorage"):WaitForChild("Disconnect")
Instance.new("RemoteEvent").Parent = game.ReplicatedStorage
game.ReplicatedStorage.RemoteEvent.Name = "Disconnect"
script.Parent = game.ServerScriptService

you make it after the event is fired, which makes no sense
by the way, OnServerEvent has a required arg which is player, so try doing

DiscEvent.OnServerEvent:Connect(function(player, KickUser)
1 Like

I’m actually not awake today :man_facepalming:

1 Like

I assume you are making some sort of admin interface. For example, kicking the player directly from a Gui rather than commands. Anyways, rather than having a TextBox object with a name, I would suggest a drop down menu that lists all of the players, so there is no misspelling errors in the process. Secondly, rather than sending the player name through the RemoteEvent, send the player object. Then on the server check if it is a player, kicking that player. Another thing I see, not necessarily the issue, is that you have the “Disconnect” RemoteEvent instanced in a somewhat odd way. I would recommend making the variable:
DiscEvent = Instance.new("RemoteEvent")
Then afterward define its parent, name, etc.

This is actually sort of a drop down menu.
image
It’s solved now anyway

Not relevant to the question, but please add protection (even if it just searches for the gui) to the script to keep exploiters from mass kicking (or kicking using this event at all!!) and kick them instead if they abuse remotes.

Anyway, good luck!

The UI is stored in the server and is inserted if they are above a certain rank in a group. If a button is pressed when they aren’t above a rank then they’ll get kicked.

It still doesn’t work for some odd reason. I’ve triple checked all my scripts and it fails to work.

Could you send me the edited version of your script please?

Sure,

script.Parent = game.ServerScriptService

local DiscEvent = game:GetService("ReplicatedStorage"):WaitForChild("Disconnect")


	

DiscEvent.OnServerEvent:Connect(function(KickUser)
	
	local PlayerKick = game.Players:FindFirstChild(KickUser)

PlayerKick:Kick("Administrative Kick: An administrator has removed you from the game")	
end)

It should look something like this:

remote.OnServerEvent:Connect(function(player, kickuser)
    if game.Players:FindFirstChild(kickuser) then
        if (rankcheck) then
            player:Kick("Administrative Kick: An administrator has removed you from the game")
        else
            player:Kick("Abusing remotes!")
        end
    end
end)

(obviously you’d add the rank check, i dont know how you’d do it, but this is only an example.)

Err, this doesnt seem like a full script. Could you also send me the local script?
Also the example above is a good one.

local DisconnectEvent = game:GetService("ReplicatedStorage"):WaitForChild("Disconnect")

script.Parent.MouseButton1Click:Connect(function()
	local KickUser = script.Parent.Parent.Parent.PlrName.Text
	DisconnectEvent:FireServer(KickUser)
end)

This is pretty similar just with the rank thing. I’m adding the rank thing after this is finished, I only started the UI today.

You didnt put player as the first argument again for the server event. That’s your problem.

Player is a required arg, and must be put first. Then, you can put your arguments. ex: (player, args)

1 Like

How would I do this then? KickUser is the player.

Ah ok. Feel free to use mine as a base if you’d like! :happy3:

1 Like
DiscEvent.OnServerEvent:Connect(function(player, KickUser))

Player is just referencing the player who fired the argument.

Description straight from the API:
– The Player associated with the client that the FireServer call originates from.

Try editing your original script by just putting player as the first argument, then kick player.

3 Likes