Advertisement
rblxdevofficial

/kick command

Jul 5th, 2022
2,179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.87 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2.  
  3. local kickCommand = "/kick "
  4.  
  5. local function onOwnerChatted(player, message)
  6.     if message:sub(1, kickCommand:len()):lower() == kickCommand:lower() then
  7.         local name = message:sub(kickCommand:len() + 1)
  8.         local playerToKick = Players:FindFirstChild(name)
  9.         if playerToKick then
  10.             playerToKick:Kick("You have been kicked by the owner.")
  11.         else
  12.             -- Couldn't find the player in question
  13.         end
  14.     end
  15. end
  16.  
  17. local function onPlayerAdded(player)
  18.     -- Restrict this command to only the creator/owner
  19.     if player.UserId == game.CreatorId and game.CreatorType == Enum.CreatorType.User then
  20.         player.Chatted:Connect(function (...)
  21.             onOwnerChatted(player, ...)
  22.         end)
  23.     end
  24. end
  25.  
  26. -- Listen for players being added
  27. for _, player in pairs(Players:GetPlayers()) do
  28.     onPlayerAdded(player)
  29. end
  30. Players.PlayerAdded:Connect(onPlayerAdded)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement