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)
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);
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)
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)