Advertisement
HowToRoblox

CommandHandler

Feb 10th, 2023
1,420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.10 KB | None | 0 0
  1. local prefix = ":" --The prefix before commands
  2.  
  3. local playerPermissions = { --Permission levels for commands - a level of 0 in a command ModuleScript means anyone can use the command
  4.     [1] = {},
  5.     [2] = {},
  6.     [3] = {84182809},
  7. }
  8.  
  9.  
  10. local cmds = game:GetService("ServerStorage"):WaitForChild("Commands")
  11.  
  12.  
  13. game.Players.PlayerAdded:Connect(function(plr)
  14.    
  15.     local plrPermission = 0
  16.    
  17.     for permissionLevel, playersAtPermission in pairs(playerPermissions) do
  18.        
  19.         if table.find(playersAtPermission, plr.UserId) then
  20.             plrPermission = permissionLevel
  21.             break
  22.         end
  23.     end
  24.    
  25.     plr.Chatted:Connect(function(message)
  26.        
  27.         local prefixMessage = string.sub(message, 1, 1)
  28.  
  29.         if prefixMessage == prefix then
  30.            
  31.             local afterPrefixMessage = string.sub(message, 2, -1)
  32.             local splitMessage = string.split(afterPrefixMessage, " ")
  33.            
  34.             local command = splitMessage[1]
  35.             if cmds:FindFirstChild(command) then
  36.                
  37.                 local arguments = splitMessage
  38.                 table.remove(arguments, 1)
  39.                
  40.                 local cmdFunction = require(cmds[command])
  41.                 cmdFunction(plr, plrPermission, arguments)
  42.             end
  43.         end
  44.     end)
  45. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement