Remote Event to Kick Players?

I’m new to scripting and I am trying to make a remote event to kick Players. I can see what the problem is (I think) is that I’m not referencing the player but I don’t know how if anybody could help me.

Script:

game.ReplicatedStorage.Kick.OnServerEvent:Connect(function(Player)
Player:Kick(“You’re not welcome here at the moment. :)”)
end)

Is this in the server? If so, are you calling :FireServer() on the client?

This is a server side script and the script where I call :FireServer() is on a localscript

Try printing “Player” and see what it says.

It didn’t work at all. I think it might be because I’m not referencing the player.

Show us your local script code. Could be a problem with how you’re using the remote event

for variable9, variable10 in pairs(Players:GetChildren()) do
if string.lower(refer) == string.lower(string.sub(variable10.Name, 1, string.len(refer))) then
Kick:FireServer(variable10);

btw I don’t know what to name variables so I’m messy

Refer is
local refer = string.sub(Text, string.len(":kick ") + 1)

I’m making an admin commands gui and since regular script didn’t work I’m using local script and I just found out you needed remote events since it didn’t work without them

Are you trying to kick the player who fired the remote? The first argument for OnServerEvent is always the player who fired the remoteEvent

Yes, I am. I’ve been looking at youtube tutorials all day and still cant find one for firing kick events so I asked on devforum

You don’t need the variable10 in the FireServer part. Also I would highly, highly suggest giving your variables way better and more descriptive names, as this is pretty much impossible to understand without background context.

Secondly, what you’re doing right now will kick whoever fired the RemoteEvent, which probably isn’t what you want, so you’ll need to pass the text ox’s text through the RemoteEvent as well, then receive it on the ServerSide.

Yeah, I just have a friend that taught me the string.len and string.sub and how to use it for admin commands and he kinda named the variables that.

local Players = game:GetService("Players")

game.ReplicatedStorage:WaitForChild("Kick").OnServerEvent:Connect(function(Player)
    if Players:FindFirstChild(Player) then
        Player:Kick("Your access to this experience has been denied!")
    end
end)

Make sure to utilize sanity checks, to make sure the player object exists! Remember, exploiters can access remotes, meaning if they fire it, the remote may not pass the player parameter.

All you need is 1 thing:

  • Server Script
Sever script basically just connections to your message and check if the prefix is stated (you can add if it's admin only) and then finds the player name and kicks 'em!.

game:GetService("Players").PlayerAdded:Connect(function(plr)
	
	plr.Chatted:Connect(function(msg)
		
		print("messaged")

local function Kick(message)

			local test = message 


			local player
			local first
			local second 
			local third

			if test:sub(0,6):match("/kick:") then
				print("prefix is correct")   

					for i,v in pairs(game:GetService("Players"):GetChildren()) do

					 	first = string.find(test, " ")
						
					
						if first == 7 then
							second = string.sub(test, 8, 99)
						
						else
							second = string.sub(test, 7, 99)
						
						end
					
						third = string.match(v.Name:lower(), second)
	
						if third then

							player = v
							player:Kick("Bye")
						end
					
					end

			else


			end	
		end

               -- you most likely want this to be admin based to just delete the first "--" below
               -- if table.find(Table, plr.UserId) then -- replace Table with your table filled with admin userid's
		Kick(msg)
               -- end  -- yeah delete these "--" in front of the end
end)
	
end)

Pardon, I believe you have the wrong person! I didn’t create this thread, apologies! :slightly_smiling_face:

1 Like

I think they wanna use GUI objects, not chat messages, however your script would work well for chat commands.

To use GUI objects, he has to use local scripts and remote events.