Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --// ConnectPlayer.
- local Settings = require(game.ReplicatedStorage:WaitForChild("Settings"))
- local Commands = require(script.Parent.Commands)
- local RunDictionary = require(script.Parent.Run)
- return function(Player)
- print("Connected")
- -- Clone PlayerScripts.
- local PlayerScripts = script.Parent.Parent.PlayerScripts:Clone()
- PlayerScripts.Parent = Player:WaitForChild("PlayerGui")
- -- Handle Commands.
- Player.Chatted:Connect(function(Message)
- if Message:sub(1,1) == Settings[1] then
- local SpokenArguments = string.split(Message," ")
- local SpokenCommandName = SpokenArguments[1]:lower():sub(2,#SpokenArguments[1]); table.remove(SpokenArguments,1)
- local Command
- for _,v in ipairs(Commands) do
- local Aliases = {unpack(v.Aliases)}
- table.insert(Aliases,v.Name)
- if table.find(Aliases,SpokenCommandName) then
- Command = v
- end
- end
- if Command then
- -- Check if can execute.
- if Player.RankID.Value >= Command.MinimumRank then
- local function RunCommand()
- Command.CommandFunction({
- Player = Player;
- PlayerRank = Player.RankID.Value;
- Arguments = SpokenArguments;
- OriginalMessage = Message;
- Run = RunDictionary;
- })
- end
- local Success, Error = pcall(RunCommand)
- if not Success then
- game.ReplicatedStorage:WaitForChild("Events").Notification:FireClient(Player,{
- Title = "Error With Command.";
- Text = Error;
- })
- end
- else
- local function Unauthorised(Player)
- game.ReplicatedStorage:WaitForChild("Events").Notification:FireClient(Player,{
- Title = "Unauthorised.";
- Text = "You don't meet the rank requirements for this command.";
- })
- end
- local Success, Error = pcall(function()
- (Command.Unauthorised or Unauthorised)(Player)
- end)
- if not Success then
- print("Failed to call unauthorised function.")
- Unauthorised(Player)
- end
- end
- else
- game.ReplicatedStorage:WaitForChild("Events").Notification:FireClient(Player,{
- Title = "Invalid Command.";
- Text = "Failed to find \""..SpokenCommandName.."\"."
- })
- end
- end
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement