Help with kick script plesae

i tried
local plrtokick = game.Players:GetPlayerByUserId()
local plrtokick = game.Players:GetPlayerNameByUserId()
local plrtokick = game.Players.Name
i need help
normal script:

	local rep = game:GetService("ReplicatedStorage")
	local rem = rep:WaitForChild("RemoteEvent")
	local rem2 = rep:WaitForChild("rem2")
	if plr.UserId == 3362150894 then 
		rem:FireClient(plr)
		wait(6.1)
	
		
	end
	rem2.OnServerEvent:Connect(function(plr)
		plr.Chatted:Connect(function(msg)
			local plrtokick = game.Players.Name
			if msg == "kick"..plrtokick then
		  plrtokick:Kick()
			
				end
				end)
				end)
end) 

uh can you tell what are you trying to do?

1 Like

Command: “kick butter5432m”

what happens:
butter5432m is kicked

so you are trying to kick yourself?

1 Like

i used my name as an example
i want to kick anyone that i want
that is in the server
im making admin commands for MYself and this is the 1st step

1 Like

Here man try this:

local ReplicatedStorage = game:GetService("ReplicatedStorage"); -- Getting the ReplicatedStorage service.
local RemoteEvent2 = ReplicatedStorage:WaitForChild("rem2"); -- Getting the 'rem2' RemoteEvent.
local Players = game:GetService("Players"); -- Getting the Players service.

local Admins = { -- Making a table of admins so you can add more admins just by inserting their UserId!
    3362150894;
    1448298878;
};

RemoteEvent2.OnServerEvent:Connect(function(player) -- When this RemoteEvent is fired to server.
    for _, v in pairs(Admins) do
        if player.UserId == v then -- If the UserId is matched with any one given in the table then;
            player.Chatted:Connect(function(msg) -- When the player messaged.
                for _, v2 in pairs(Players:GetPlayers()) do -- Looping through all the players currently in the server.
                    if msg == "kick " .. v.Name then -- If the message is 'kick butter5432m' then; (used your name as an example lol)
                        v2:Kick(); -- It will kick the player;
                    end;
                end;
            end);
        end;
    end;
end);

(Given with explanation)

2 Likes
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
	if Player.UserId == 3362150894 then
		Player.Chatted:Connect(function(msg)
			if msg then
				local message = string.split(msg, " ")
				if message[1] and message[2] then
					if message[1] == "kick" and Players:FindFirstChild(message[2]) then
						Players:FindFirstChild(message[2]):Kick()
					end
				end
			end
		end
	end
end)
1 Like

You don’t need a for loop to loop through the Admin table. You can simple use table.find() like this:

local Players = game:GetService("Players")

local Admins = {
	3362150894,
	1,
	2,
}

Players.PlayerAdded:Connect(function(Player)
	if table.find(Admins, Player.UserId) then
		Player.Chatted:Connect(function(msg)
			if msg then
				local message = string.split(msg, " ")
				if message[1] and message[2] then
					if message[1] == "kick" and Players:FindFirstChild(message[2]) then
						Players:FindFirstChild(message[2]):Kick()
					end
				end
			end
		end
	end
end)
1 Like

back from going out
can u explain why u added message[1] and message [2]

I split the message in 2.
message[1] is “kick” and message[2] is the user.
That is how I got the player instead of using a for loop

1 Like