Advertisement
Alexplazz

Untitled

Oct 20th, 2021
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. --// ConnectPlayer.
  2. local Settings = require(game.ReplicatedStorage:WaitForChild("Settings"))
  3. local Commands = require(script.Parent.Commands)
  4. local RunDictionary = require(script.Parent.Run)
  5. return function(Player)
  6. print("Connected")
  7. -- Clone PlayerScripts.
  8. local PlayerScripts = script.Parent.Parent.PlayerScripts:Clone()
  9. PlayerScripts.Parent = Player:WaitForChild("PlayerGui")
  10.  
  11. -- Handle Commands.
  12. Player.Chatted:Connect(function(Message)
  13. if Message:sub(1,1) == Settings[1] then
  14. local SpokenArguments = string.split(Message," ")
  15. local SpokenCommandName = SpokenArguments[1]:lower():sub(2,#SpokenArguments[1]); table.remove(SpokenArguments,1)
  16.  
  17. local Command
  18. for _,v in ipairs(Commands) do
  19. local Aliases = {unpack(v.Aliases)}
  20. table.insert(Aliases,v.Name)
  21. if table.find(Aliases,SpokenCommandName) then
  22. Command = v
  23. end
  24. end
  25. if Command then
  26. -- Check if can execute.
  27. if Player.RankID.Value >= Command.MinimumRank then
  28. local function RunCommand()
  29. Command.CommandFunction({
  30. Player = Player;
  31. PlayerRank = Player.RankID.Value;
  32. Arguments = SpokenArguments;
  33. OriginalMessage = Message;
  34. Run = RunDictionary;
  35. })
  36. end
  37. local Success, Error = pcall(RunCommand)
  38. if not Success then
  39. game.ReplicatedStorage:WaitForChild("Events").Notification:FireClient(Player,{
  40. Title = "Error With Command.";
  41. Text = Error;
  42. })
  43. end
  44. else
  45. local function Unauthorised(Player)
  46. game.ReplicatedStorage:WaitForChild("Events").Notification:FireClient(Player,{
  47. Title = "Unauthorised.";
  48. Text = "You don't meet the rank requirements for this command.";
  49. })
  50. end
  51. local Success, Error = pcall(function()
  52. (Command.Unauthorised or Unauthorised)(Player)
  53. end)
  54. if not Success then
  55. print("Failed to call unauthorised function.")
  56. Unauthorised(Player)
  57. end
  58. end
  59. else
  60. game.ReplicatedStorage:WaitForChild("Events").Notification:FireClient(Player,{
  61. Title = "Invalid Command.";
  62. Text = "Failed to find \""..SpokenCommandName.."\"."
  63. })
  64. end
  65. end
  66. end)
  67. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement