:Kick() is not working on other players for some reason

I’m trying to make a kick part of a GUI. It’s rather simple, once a TextBox’s focus is lost, it finds the closest player in the server matching the input, fires an event, and kicks them. However, it only works on the person who is the person kicking, and will not kick anybody else. Could I get some help?

Local script:

local textBox = script.Parent.Input
local players = game.Players
local event = game.ReplicatedStorage.PrivateServerGUIEvents.Kick

function input(e)
	if e then
		if textBox.Text:len() >= 4 then
			local possiblePlayers = {}
			for i, v in pairs(game.Players:GetChildren()) do
				if string.find(string.lower(v.Name), string.lower(textBox.Text)) then
					table.insert(possiblePlayers, i, v)
			if #possiblePlayers == 1 then


Server script:

local event = game.ReplicatedStorage.PrivateServerGUIEvents.Kick

function kick(p, t)
	for i, v in pairs(t) do
		v:Kick("You were kicked by the private server owner.")


The local script is under a GUI in StarterGui, the event is in a folder in ReplicatedStorage, and the server script is in a folder in ServerScriptService.

Did you try printing possiblePlayers?
I think the problem is your string.find. You should use this:

if string.match(string.lower(v.Name), "^"..string.lower(textBox.Text)) then

This checks if the player name starts with the given name.

I used string.find() as it allows me to type “sans” and not have to type the full “sansprosii”.

Also, it still kicks me, why not others when I try them?

My code does that too.

Did you print possiblePlayers?

Nope, he inserts player instances in the table. Otherwise it wouldn’t be able to kick him.

Yeah i saw kinda skipped over that lol but why is he searching for the player in such a complicated way?

Because he wants to be able to find players by just typing a part of their name, not the whole name.

I printed the table, and got the name of the player I inputted. No kick at all, even with your line of code.

The error must be based on the server I assume.

try printing v when you do i,v

also side note you should prob have a server check that thats the legit private server owner and not some random guy on synapse

It printed both people in the server.


Just remade this by using string.sub


script.Parent.playername.FocusLost:Connect(function() ---your textbox
	local text = script.Parent.playername.Text:lower() --textbox text
	for i, v in pairs(game.Players:GetPlayers()) do
		if string.sub(text,1,text:len()) == string.sub(v.Name:lower(),1,text:len()) then
			local foundplr = v


local event = game.ReplicatedStorage.PrivateServerGUIEvents


Also make sure that its a private server.

I found a solution! So, replacing the for loop with a singular if statement somehow fixes it. Idk why, but at least its over with now.