Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ADMIN COMMAND SYSTEM
- local Players = game:GetService("Players")
- local DataStoreService = game:GetService("DataStoreService")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local NotificationEvent = ReplicatedStorage:WaitForChild("NotificationEvent")
- local function notify(player, title, text, duration)
- NotificationEvent:FireClient(player, title, text, duration or 3)
- end
- local function safeGetDataStore(name)
- local success, store = pcall(function()
- return DataStoreService:GetDataStore(name)
- end)
- return success and store or {
- _data = {},
- GetAsync = function(self, key) return self._data[key] end,
- SetAsync = function(self, key, value) self._data[key] = value end
- }
- end
- local RankStore = safeGetDataStore("PlayerRanks")
- local WarningStore = safeGetDataStore("PlayerWarnings")
- local DefaultRank = "Guest"
- local EditableRanks = {"Owner", "Developer"}
- local PermanentRanks = {
- Owner = {"YourUsername1"},
- Developer = {"YourUsername2"},
- Admin = {"YourUsername3"},
- Moderator = {},
- VIP = {},
- Youtuber = {},
- Tester = {},
- Support = {}
- }
- local RankData = {}
- local AllCommands = {
- "fly", "unfly", "kick", "ban", "unban", "speed", "unspeed", "jump", "unjump", "invisible", "visible",
- "time", "day", "night", "health", "kill", "god", "ungod", "freeze", "unfreeze", "size", "reset", "tools",
- "notools", "sit", "unsit", "walkspeed", "name", "noname", "warn", "warnings"
- }
- local CommandPermissions = {
- Owner = AllCommands,
- Developer = {
- "fly", "unfly", "speed", "unspeed", "jump", "unjump", "tools", "notools", "invisible", "visible",
- "sit", "unsit", "name", "noname", "size", "reset", "day", "night", "health", "god", "ungod",
- "freeze", "unfreeze", "warn", "warnings"
- },
- Admin = {
- "fly", "unfly", "speed", "unspeed", "jump", "unjump", "tools", "notools", "sit", "unsit", "reset",
- "size", "health", "god", "ungod", "warn", "warnings"
- },
- Moderator = {
- "fly", "unfly", "speed", "unspeed", "sit", "unsit", "reset", "tools", "notools", "jump",
- "warn", "warnings"
- }
- }
- local function saveRank(userId, rank)
- pcall(function() RankStore:SetAsync(tostring(userId), rank) end)
- end
- local function loadRank(player)
- local userId, username = player.UserId, player.Name
- for rankName, list in pairs(PermanentRanks) do
- for _, name in ipairs(list) do
- if name == username then return rankName end
- end
- end
- local success, result = pcall(function()
- return RankStore:GetAsync(tostring(userId))
- end)
- if success and result then return result end
- return DefaultRank
- end
- local function addWarning(target, reason)
- local key = tostring(target.UserId)
- local warnings = {}
- local success, result = pcall(function()
- return WarningStore:GetAsync(key)
- end)
- if success and type(result) == "table" then warnings = result end
- table.insert(warnings, reason .. " at " .. os.date("%x %X"))
- pcall(function() WarningStore:SetAsync(key, warnings) end)
- end
- local function getWarnings(target)
- local success, result = pcall(function()
- return WarningStore:GetAsync(tostring(target.UserId))
- end)
- return success and result or {}
- end
- local function sendHelp(player)
- local rank = RankData[player.UserId] or DefaultRank
- local cmds = CommandPermissions[rank] or {}
- notify(player, "Available Commands", "/" .. table.concat(cmds, "\n/"), 10)
- end
- local function getTargetList(sourcePlayer, input)
- input = input:lower()
- local list = {}
- if input == "all" then
- for _, p in ipairs(Players:GetPlayers()) do table.insert(list, p) end
- elseif input == "others" then
- for _, p in ipairs(Players:GetPlayers()) do
- if p ~= sourcePlayer then table.insert(list, p) end
- end
- else
- local p = Players:FindFirstChild(input)
- if p then table.insert(list, p) end
- end
- return list
- end
- local function executeCommand(player, cmd, args)
- local targets = getTargetList(player, args[2])
- local arg3 = args[3]
- for _, target in ipairs(targets) do
- if cmd == "fly" then
- target.Character:FindFirstChildOfClass("Humanoid").PlatformStand = true
- elseif cmd == "unfly" then
- target.Character:FindFirstChildOfClass("Humanoid").PlatformStand = false
- elseif cmd == "speed" then
- target.Character.Humanoid.WalkSpeed = tonumber(arg3) or 50
- elseif cmd == "unspeed" then
- target.Character.Humanoid.WalkSpeed = 16
- elseif cmd == "jump" then
- target.Character.Humanoid.JumpPower = tonumber(arg3) or 100
- elseif cmd == "unjump" then
- target.Character.Humanoid.JumpPower = 50
- elseif cmd == "freeze" then
- target.Character.HumanoidRootPart.Anchored = true
- elseif cmd == "unfreeze" then
- target.Character.HumanoidRootPart.Anchored = false
- elseif cmd == "kill" then
- target:Kick("You were killed by an admin")
- elseif cmd == "reset" then
- target:LoadCharacter()
- elseif cmd == "sit" then
- target.Character.Humanoid.Sit = true
- elseif cmd == "unsit" then
- target.Character.Humanoid.Sit = false
- elseif cmd == "god" then
- target.Character.Humanoid.MaxHealth = math.huge
- target.Character.Humanoid.Health = math.huge
- elseif cmd == "ungod" then
- target.Character.Humanoid.MaxHealth = 100
- target.Character.Humanoid.Health = 100
- elseif cmd == "tools" then
- -- You can insert tools here
- elseif cmd == "notools" then
- for _, tool in ipairs(target.Backpack:GetChildren()) do
- tool:Destroy()
- end
- elseif cmd == "name" and arg3 then
- target.DisplayName = arg3
- elseif cmd == "noname" then
- target.DisplayName = target.Name
- end
- end
- notify(player, "Command", "Executed: /" .. cmd, 2)
- end
- local function onChatted(player, msg)
- local args = msg:split(" ")
- local cmd = args[1]:sub(2):lower()
- local senderRank = RankData[player.UserId] or DefaultRank
- if cmd == "rank" and args[2] and args[3] then
- if table.find(EditableRanks, senderRank) then
- local target = Players:FindFirstChild(args[2])
- local rank = args[3]
- if target and PermanentRanks[rank] then
- RankData[target.UserId] = rank
- target:SetAttribute("Rank", rank)
- saveRank(target.UserId, rank)
- notify(player, "Rank Updated", "Gave " .. target.Name .. " the rank: " .. rank, 3)
- end
- end
- elseif cmd == "removerank" and args[2] then
- if table.find(EditableRanks, senderRank) then
- local target = Players:FindFirstChild(args[2])
- if target then
- RankData[target.UserId] = DefaultRank
- target:SetAttribute("Rank", DefaultRank)
- saveRank(target.UserId, DefaultRank)
- notify(player, "Rank Removed", target.Name .. " is now a Guest", 3)
- end
- end
- elseif cmd == "rankhelp" then
- sendHelp(player)
- elseif cmd == "warn" and args[2] and args[3] then
- if table.find(CommandPermissions[senderRank] or {}, "warn") then
- local target = Players:FindFirstChild(args[2])
- local reason = table.concat(args, " ", 3)
- if target then
- addWarning(target, reason)
- notify(player, "Warn", "Warned " .. target.Name, 3)
- end
- end
- elseif cmd == "warnings" and args[2] then
- if table.find(CommandPermissions[senderRank] or {}, "warnings") then
- local target = Players:FindFirstChild(args[2])
- if target then
- local warnings = getWarnings(target)
- if #warnings > 0 then
- notify(player, target.Name .. "'s Warnings", table.concat(warnings, "\n"), 10)
- else
- notify(player, "Warnings", "No warnings found.", 3)
- end
- end
- end
- elseif table.find(CommandPermissions[senderRank] or {}, cmd) then
- executeCommand(player, cmd, args)
- end
- end
- Players.PlayerAdded:Connect(function(player)
- local rank = loadRank(player)
- RankData[player.UserId] = rank
- player:SetAttribute("Rank", rank)
- player.Chatted:Connect(function(msg)
- if msg:sub(1, 1) == "/" then
- onChatted(player, msg)
- end
- end)
- end)
Advertisement
Add Comment
Please, Sign In to add comment