Kick Player Script Not Working, No Errors In Output

  1. What do you want to achieve? Kick The Player By Inputting There Name Into A Text Box, then pressing a button to fire a RemoteEvent, which then kicks the given player.

  2. What is the issue? Script Not Working, No Errors In Output, Debug print() statements not running.

  3. What solutions have you tried so far? Changing my scripts and looking on the devforum

Local Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local btn = script.Parent --Gui Button Which Fires The Function
local textbox = script.Parent.Parent.KickInput --Gui Textbox where you Input Player Name
local RemoteEvent = ReplicatedStorage.KickEvent --The RemoteEvent

btn.MouseButton1Up:Connect(function()
	local text = textbox.Text
	if Players:FindFirstChild(text) then
		RemoteEvent:FireServer(text)
	end
end)

Script

local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

RemoteEvent.OnServerEvent:Connect(function(plr, text)
	print(text)
	Players:FindFirstChild(text):Kick("Kicked By An Admin")
	print("Kicked")
end)

I will also add that this is my time using RemoteEvents, so I might have made a simple mistake.

1 Like

This is unnecessary, the player is already defined by the parameters. Just replace that line of code with

plr:Kick("Kicked By An Admin")

the plr in the parameter is the one who ran the RemoteEvent, So as far as I know that would kick myself? I will try it though.

Hi! This actually wouldn’t work, because the plr parameter here is the client triggering the remote event, not the player that needs to be kicked.

Wait, you are right. Sorry, I didn’t read your entire post.

I believe I have a solution to the problem:

Local Script:

local Players = game:GetService("Players")
local remoteEvent = game:GetService("ReplicatedStorage").KickEvent
local button = script.Parent
local kickInputBox = script.Parent.Parent.KickInput

button.MouseButton1Click:Connect(function()
	local plrName = kickInputBox.Text
	if Players:FindFirstChild(plrName) then
		remoteEvent:FireServer(Players:FindFirstChild(plrName))
	end
end)

Server Script:

local remoteEvent = game:GetService("ReplicatedStorage").KickEvent

remoteEvent.OnServerEvent:Connect(function(_,plrToKick)
	plrToKick:Kick("Kick message goes here!")
end)

I tested this in studio and it worked for me. If you’re still having issues, try printing various test messages to ensure that the remote event is firing correctly, and plrToKick is the correct player.

Hope this helps!

Edit:
If you don’t want typing in the player’s name to be case-sensitive, you’ll need to loop through all the players like this:

-- Inside button.MouseButton1Click
local plrName = kickInputBox.Text:lower()
for i, plr in pairs(Players:GetPlayers()) do
	if plr.Name:lower() == plrName then
		remoteEvent:FireServer(plr)
		return -- No need to keep looping, so end the function here
	end
end
1 Like

I will try this and see if this fixes my problem, thank you for the quick response!

1 Like

This is asking for trouble you should validate the person firing the remote is actually a mod/the owner.

dont some names have capitals aswell?, might be a issue if you type the name in all lower

I have it so the gui only appears for me

exploiters can bypass that

(char limit)

An exploit could be used to fire the remote regardless.

Judging by how sub-par my lua skills are, I doubt exploiters will even FIND my game

Also have no objective of advertising at the moment, its just a personal project to practice

No need to think that way instead treat this as an opportunity to learn/try things besides validating the person firing the remote is quite simple

Event.OnServerEvent:Connect(function(Who, Target)
	if Who.UserId ~= YourUserId then
		Who:Kick("The last time i checked my name wasn't "..Who.Name..".")
		return --Ends the function
	end

	Target:Kick("You were kicked by an admin.")
end)
3 Likes

Also if you’re planning on having many remotes for various actions that requires conditions to be usable like having an item equipped i recommend using codes rather than describing what went wrong.

Who:Kick("Invalid remote request. [Q]") --Q isnt a key its a number in qwerty you'd go q w e r t etc. all the way to the last key then start going QQ QW QE QR QT QY etc. then WQ WW WE WR its easy to keep track of

Doing this will make things harder to understand for exploiters while still keeping it relatively possible to keep track of for you in case an actual bug were to accur and kick an innocent player.

1 Like

i made a slight adjustment to the local script and this should check if the player is an admin or not

local button = script.Parent
local Players = game:GetService("Players")
local Admins = {1,2,3} -- Put user id's here and seperate them with ","
local plr = Players.LocalPlayer
button.MouseButton1Down:Connect(function() 
	if table.find(Admins,plr.UserId) then -- checks if the player's user id matches with one from the table
		-- Script here
	else
		print("Player's userId does not match")
	end
end)

table.find() can be slow depending on how many ids you’re working on, use this instead!

local button = script.Parent
local Players = game:GetService("Players")
local Admins = {
	[PlayerId] = true,
	[AnotherPlayerId] = true
} -- Put user id's here and set em to true
local plr = Players.LocalPlayer
button.MouseButton1Down:Connect(function() 
	if Admins[plr.UserId] then -- checks if the player's user id matches with one from the table
		-- Script here
	else
		print("Player's userId does not match")
	end
end)

Tho ideally you shouldn’t even be loading any admin scripts to non-admin users and all admin checks should be done on server side since its possible to decompile lua scripts to a certain extent.