Guest User

Admin commands script

a guest
May 22nd, 2025
565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.64 KB | Gaming | 0 0
  1. -- ADMIN COMMAND SYSTEM
  2.  
  3. local Players = game:GetService("Players")
  4. local DataStoreService = game:GetService("DataStoreService")
  5. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  6.  
  7. local NotificationEvent = ReplicatedStorage:WaitForChild("NotificationEvent")
  8.  
  9. local function notify(player, title, text, duration)
  10.     NotificationEvent:FireClient(player, title, text, duration or 3)
  11. end
  12.  
  13. local function safeGetDataStore(name)
  14.     local success, store = pcall(function()
  15.         return DataStoreService:GetDataStore(name)
  16.     end)
  17.     return success and store or {
  18.         _data = {},
  19.         GetAsync = function(self, key) return self._data[key] end,
  20.         SetAsync = function(self, key, value) self._data[key] = value end
  21.     }
  22. end
  23.  
  24. local RankStore = safeGetDataStore("PlayerRanks")
  25. local WarningStore = safeGetDataStore("PlayerWarnings")
  26.  
  27. local DefaultRank = "Guest"
  28. local EditableRanks = {"Owner", "Developer"}
  29.  
  30. local PermanentRanks = {
  31.     Owner = {"YourUsername1"},
  32.     Developer = {"YourUsername2"},
  33.     Admin = {"YourUsername3"},
  34.     Moderator = {},
  35.     VIP = {},
  36.     Youtuber = {},
  37.     Tester = {},
  38.     Support = {}
  39. }
  40.  
  41. local RankData = {}
  42.  
  43. local AllCommands = {
  44.     "fly", "unfly", "kick", "ban", "unban", "speed", "unspeed", "jump", "unjump", "invisible", "visible",
  45.     "time", "day", "night", "health", "kill", "god", "ungod", "freeze", "unfreeze", "size", "reset", "tools",
  46.     "notools", "sit", "unsit", "walkspeed", "name", "noname", "warn", "warnings"
  47. }
  48.  
  49. local CommandPermissions = {
  50.     Owner = AllCommands,
  51.     Developer = {
  52.         "fly", "unfly", "speed", "unspeed", "jump", "unjump", "tools", "notools", "invisible", "visible",
  53.         "sit", "unsit", "name", "noname", "size", "reset", "day", "night", "health", "god", "ungod",
  54.         "freeze", "unfreeze", "warn", "warnings"
  55.     },
  56.     Admin = {
  57.         "fly", "unfly", "speed", "unspeed", "jump", "unjump", "tools", "notools", "sit", "unsit", "reset",
  58.         "size", "health", "god", "ungod", "warn", "warnings"
  59.     },
  60.     Moderator = {
  61.         "fly", "unfly", "speed", "unspeed", "sit", "unsit", "reset", "tools", "notools", "jump",
  62.         "warn", "warnings"
  63.     }
  64. }
  65.  
  66. local function saveRank(userId, rank)
  67.     pcall(function() RankStore:SetAsync(tostring(userId), rank) end)
  68. end
  69.  
  70. local function loadRank(player)
  71.     local userId, username = player.UserId, player.Name
  72.     for rankName, list in pairs(PermanentRanks) do
  73.         for _, name in ipairs(list) do
  74.             if name == username then return rankName end
  75.         end
  76.     end
  77.     local success, result = pcall(function()
  78.         return RankStore:GetAsync(tostring(userId))
  79.     end)
  80.     if success and result then return result end
  81.     return DefaultRank
  82. end
  83.  
  84. local function addWarning(target, reason)
  85.     local key = tostring(target.UserId)
  86.     local warnings = {}
  87.     local success, result = pcall(function()
  88.         return WarningStore:GetAsync(key)
  89.     end)
  90.     if success and type(result) == "table" then warnings = result end
  91.     table.insert(warnings, reason .. " at " .. os.date("%x %X"))
  92.     pcall(function() WarningStore:SetAsync(key, warnings) end)
  93. end
  94.  
  95. local function getWarnings(target)
  96.     local success, result = pcall(function()
  97.         return WarningStore:GetAsync(tostring(target.UserId))
  98.     end)
  99.     return success and result or {}
  100. end
  101.  
  102. local function sendHelp(player)
  103.     local rank = RankData[player.UserId] or DefaultRank
  104.     local cmds = CommandPermissions[rank] or {}
  105.     notify(player, "Available Commands", "/" .. table.concat(cmds, "\n/"), 10)
  106. end
  107.  
  108. local function getTargetList(sourcePlayer, input)
  109.     input = input:lower()
  110.     local list = {}
  111.     if input == "all" then
  112.         for _, p in ipairs(Players:GetPlayers()) do table.insert(list, p) end
  113.     elseif input == "others" then
  114.         for _, p in ipairs(Players:GetPlayers()) do
  115.             if p ~= sourcePlayer then table.insert(list, p) end
  116.         end
  117.     else
  118.         local p = Players:FindFirstChild(input)
  119.         if p then table.insert(list, p) end
  120.     end
  121.     return list
  122. end
  123.  
  124. local function executeCommand(player, cmd, args)
  125.     local targets = getTargetList(player, args[2])
  126.     local arg3 = args[3]
  127.     for _, target in ipairs(targets) do
  128.         if cmd == "fly" then
  129.             target.Character:FindFirstChildOfClass("Humanoid").PlatformStand = true
  130.         elseif cmd == "unfly" then
  131.             target.Character:FindFirstChildOfClass("Humanoid").PlatformStand = false
  132.         elseif cmd == "speed" then
  133.             target.Character.Humanoid.WalkSpeed = tonumber(arg3) or 50
  134.         elseif cmd == "unspeed" then
  135.             target.Character.Humanoid.WalkSpeed = 16
  136.         elseif cmd == "jump" then
  137.             target.Character.Humanoid.JumpPower = tonumber(arg3) or 100
  138.         elseif cmd == "unjump" then
  139.             target.Character.Humanoid.JumpPower = 50
  140.         elseif cmd == "freeze" then
  141.             target.Character.HumanoidRootPart.Anchored = true
  142.         elseif cmd == "unfreeze" then
  143.             target.Character.HumanoidRootPart.Anchored = false
  144.         elseif cmd == "kill" then
  145.             target:Kick("You were killed by an admin")
  146.         elseif cmd == "reset" then
  147.             target:LoadCharacter()
  148.         elseif cmd == "sit" then
  149.             target.Character.Humanoid.Sit = true
  150.         elseif cmd == "unsit" then
  151.             target.Character.Humanoid.Sit = false
  152.         elseif cmd == "god" then
  153.             target.Character.Humanoid.MaxHealth = math.huge
  154.             target.Character.Humanoid.Health = math.huge
  155.         elseif cmd == "ungod" then
  156.             target.Character.Humanoid.MaxHealth = 100
  157.             target.Character.Humanoid.Health = 100
  158.         elseif cmd == "tools" then
  159.             -- You can insert tools here
  160.         elseif cmd == "notools" then
  161.             for _, tool in ipairs(target.Backpack:GetChildren()) do
  162.                 tool:Destroy()
  163.             end
  164.         elseif cmd == "name" and arg3 then
  165.             target.DisplayName = arg3
  166.         elseif cmd == "noname" then
  167.             target.DisplayName = target.Name
  168.         end
  169.     end
  170.     notify(player, "Command", "Executed: /" .. cmd, 2)
  171. end
  172.  
  173. local function onChatted(player, msg)
  174.     local args = msg:split(" ")
  175.     local cmd = args[1]:sub(2):lower()
  176.     local senderRank = RankData[player.UserId] or DefaultRank
  177.  
  178.     if cmd == "rank" and args[2] and args[3] then
  179.         if table.find(EditableRanks, senderRank) then
  180.             local target = Players:FindFirstChild(args[2])
  181.             local rank = args[3]
  182.             if target and PermanentRanks[rank] then
  183.                 RankData[target.UserId] = rank
  184.                 target:SetAttribute("Rank", rank)
  185.                 saveRank(target.UserId, rank)
  186.                 notify(player, "Rank Updated", "Gave " .. target.Name .. " the rank: " .. rank, 3)
  187.             end
  188.         end
  189.     elseif cmd == "removerank" and args[2] then
  190.         if table.find(EditableRanks, senderRank) then
  191.             local target = Players:FindFirstChild(args[2])
  192.             if target then
  193.                 RankData[target.UserId] = DefaultRank
  194.                 target:SetAttribute("Rank", DefaultRank)
  195.                 saveRank(target.UserId, DefaultRank)
  196.                 notify(player, "Rank Removed", target.Name .. " is now a Guest", 3)
  197.             end
  198.         end
  199.     elseif cmd == "rankhelp" then
  200.         sendHelp(player)
  201.     elseif cmd == "warn" and args[2] and args[3] then
  202.         if table.find(CommandPermissions[senderRank] or {}, "warn") then
  203.             local target = Players:FindFirstChild(args[2])
  204.             local reason = table.concat(args, " ", 3)
  205.             if target then
  206.                 addWarning(target, reason)
  207.                 notify(player, "Warn", "Warned " .. target.Name, 3)
  208.             end
  209.         end
  210.     elseif cmd == "warnings" and args[2] then
  211.         if table.find(CommandPermissions[senderRank] or {}, "warnings") then
  212.             local target = Players:FindFirstChild(args[2])
  213.             if target then
  214.                 local warnings = getWarnings(target)
  215.                 if #warnings > 0 then
  216.                     notify(player, target.Name .. "'s Warnings", table.concat(warnings, "\n"), 10)
  217.                 else
  218.                     notify(player, "Warnings", "No warnings found.", 3)
  219.                 end
  220.             end
  221.         end
  222.     elseif table.find(CommandPermissions[senderRank] or {}, cmd) then
  223.         executeCommand(player, cmd, args)
  224.     end
  225. end
  226.  
  227. Players.PlayerAdded:Connect(function(player)
  228.     local rank = loadRank(player)
  229.     RankData[player.UserId] = rank
  230.     player:SetAttribute("Rank", rank)
  231.     player.Chatted:Connect(function(msg)
  232.         if msg:sub(1, 1) == "/" then
  233.             onChatted(player, msg)
  234.         end
  235.     end)
  236. end)
  237.  
Advertisement
Add Comment
Please, Sign In to add comment