Advertisement
HowToRoblox

AdminServer

Oct 13th, 2022
5,543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.84 KB | None | 0 0
  1. local rs = game.ReplicatedStorage:WaitForChild("AdminPanelRS")
  2. local re = rs:WaitForChild("RE")
  3. local admins = require(rs:WaitForChild("AdminsModule"))
  4.  
  5. local ts = game:GetService("TextService")
  6.  
  7. local ms = game:GetService("MessagingService")
  8. local announcementTopic = "admin panel ANNOUNCEMENT"
  9. local banTopic = "admin panel BAN"
  10. local muteTopic = "admin panel MUTE"
  11. local unmuteTopic = "admin panel UNMUTE"
  12. local kickTopic = "admin panel KICK"
  13.  
  14. local dss = game:GetService("DataStoreService")
  15. local ds = dss:GetDataStore("MODERATION DATASTORE")
  16.  
  17. local cs = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
  18. local channel = cs:GetChannel("ALL")
  19.  
  20. local shuttingDown = false
  21.  
  22.  
  23. --Respond to commands
  24. re.OnServerEvent:Connect(function(plr, instruction, value, targetId)
  25.    
  26.     if table.find(admins, plr.UserId) then
  27.         local adminChar = plr.Character
  28.        
  29.         local targetPlr
  30.         if tonumber(targetId) then
  31.             targetPlr = game.Players:GetPlayerByUserId(tonumber(targetId))
  32.         end
  33.        
  34.         --CHARACTER COMMANDS
  35.         if tonumber(targetId) then
  36.             targetId = tonumber(targetId)
  37.             if targetPlr and targetPlr.Character then
  38.                 local targetChar = targetPlr.Character
  39.                
  40.                 if instruction == "GO TO" and adminChar then
  41.                     adminChar.HumanoidRootPart.CFrame = targetChar.HumanoidRootPart.CFrame
  42.                 elseif instruction == "BRING" then
  43.                     targetChar.HumanoidRootPart.CFrame = adminChar.HumanoidRootPart.CFrame
  44.                    
  45.                 elseif instruction == "FREEZE" then
  46.                     targetChar.HumanoidRootPart.Anchored = true
  47.                 elseif instruction == "UNFREEZE" then
  48.                     targetChar.HumanoidRootPart.Anchored = false
  49.                    
  50.                 elseif instruction == "SPEED" and tonumber(value) then
  51.                     targetChar.Humanoid.WalkSpeed = tonumber(value)
  52.                 elseif instruction == "JUMP" and tonumber(value) then
  53.                     if targetChar.Humanoid.UseJumpPower == true then
  54.                         targetChar.Humanoid.JumpPower = tonumber(value)
  55.                     else
  56.                         targetChar.Humanoid.JumpHeight = tonumber(value)
  57.                     end
  58.                    
  59.                 elseif instruction == "HEALTH" and tonumber(value) then
  60.                     targetChar.Humanoid.Health = tonumber(value)
  61.                 end
  62.             end
  63.            
  64.         --MODERATION COMMANDS
  65.             if instruction == "MUTE" and tonumber(value) then
  66.                
  67.                 local muteStart = os.time()
  68.                 local muteEnd = muteStart + tonumber(value)
  69.                
  70.                 local data = {muteEnd}
  71.                
  72.                 pcall(function()
  73.                     ds:SetAsync(targetId .. "Muted", data)
  74.                    
  75.                     if targetPlr then
  76.                         channel:MuteSpeaker(targetPlr.Name)
  77.                        
  78.                         task.wait(tonumber(value))
  79.                         if targetPlr then
  80.                             channel:UnmuteSpeaker(targetPlr.Name)
  81.                         end
  82.                     else
  83.                         ms:PublishAsync(muteTopic, {targetId, tonumber(value)})
  84.                     end
  85.                 end)
  86.             elseif instruction == "UNMUTE" then
  87.                 pcall(function()
  88.                     ds:RemoveAsync(targetId .. "Muted")
  89.                    
  90.                     if targetPlr then
  91.                         channel:UnmuteSpeaker(targetPlr.Name)
  92.                     else
  93.                         ms:PublishAsync(unmuteTopic, {targetId})
  94.                     end
  95.                 end)
  96.                
  97.             elseif instruction == "BAN" and tonumber(value[1]) then
  98.                 local banStart = os.time()
  99.                 local banEnd = banStart + tonumber(value[1])
  100.                
  101.                 local banReason = value[2]
  102.                
  103.                 local data = {banEnd, banReason}
  104.                
  105.                 pcall(function()
  106.                     ds:SetAsync(targetId .. "Banned", data)
  107.                    
  108.                     local dateInfo = os.date("!*t", data[1])
  109.                     local dateFormatted = dateInfo["day"] .. "/" .. dateInfo["month"] .. "/" .. dateInfo["year"] .. "  " .. dateInfo["hour"] .. ":" .. dateInfo["min"] .. ":" .. dateInfo["sec"]
  110.                     local banMessage = "Banned for: " .. data[2] .. " | Ends: " .. dateFormatted
  111.                    
  112.                     if targetPlr then
  113.                         targetPlr:Kick(banMessage)
  114.                        
  115.                     else
  116.                         ms:PublishAsync(banTopic, {targetId, banMessage})
  117.                     end
  118.                 end)
  119.             elseif instruction == "UNBAN" then
  120.                 pcall(function()
  121.                     ds:RemoveAsync(targetId .. "Banned")
  122.                 end)
  123.                
  124.             elseif instruction == "KICK" then
  125.                 if targetPlr then
  126.                     targetPlr:Kick(value)
  127.                 else
  128.                     ms:PublishAsync(kickTopic, {targetId, value})
  129.                 end
  130.             end
  131.            
  132.         --COMMAND BAR
  133.         elseif instruction == "COMMAND BAR" and value then
  134.             pcall(function()
  135.                 loadstring(value)()
  136.             end)
  137.            
  138.         --SYSTEM COMMANDS
  139.         else
  140.             if instruction == "ANNOUNCE" and value and targetId then
  141.                 local success, filtered = pcall(function()
  142.                     local filteredTextResult = ts:FilterStringAsync(value, plr.UserId):GetNonChatStringForBroadcastAsync()
  143.                     return filteredTextResult
  144.                 end)
  145.                 if success and filtered then
  146.                    
  147.                     if targetId == "GLOBAL" then
  148.                         ms:PublishAsync(announcementTopic, {filtered})
  149.                        
  150.                     else
  151.                         re:FireAllClients("ANNOUNCE", filtered)
  152.                     end
  153.                 end
  154.                    
  155.             elseif instruction == "SHUT DOWN" then
  156.                 shuttingDown = true
  157.                
  158.                 for i, plr in pairs(game.Players:GetPlayers()) do
  159.                     plr:Kick("This server is shutting down.")
  160.                 end
  161.             end
  162.         end
  163.     end
  164. end)
  165.  
  166.  
  167. --Check moderation data
  168. game.Players.PlayerAdded:Connect(function(plr)
  169.    
  170.     --Kick new players if game is shutting down
  171.     if shuttingDown then
  172.         plr:Kick("This server has shut down.")
  173.     end
  174.    
  175.     --Kick banned players, or remove ban data if ban time is over
  176.     local banSuccess, banData = pcall(function()
  177.         local data = ds:GetAsync(plr.UserId .. "Banned")
  178.         return data
  179.     end)
  180.    
  181.     if banSuccess and banData then
  182.         local banEnd = banData[1]
  183.        
  184.         if os.time() >= banEnd then
  185.             pcall(function()
  186.                 ds:RemoveAsync(plr.UserId .. "Banned")
  187.             end)
  188.            
  189.         else
  190.             local banReason = banData[2]
  191.            
  192.             local dateInfo = os.date("!*t", banEnd)
  193.             local dateFormatted = dateInfo["day"] .. "/" .. dateInfo["month"] .. "/" .. dateInfo["year"] .. "  " .. dateInfo["hour"] .. ":" .. dateInfo["min"] .. ":" .. dateInfo["sec"]
  194.             local banMessage = "Banned for: " .. banReason .. " | Ends: " .. dateFormatted
  195.            
  196.             plr:Kick(banMessage)
  197.         end
  198.     end
  199.    
  200.     --Mute players or unmute them if mute time is over
  201.     local muteSuccess, muteData = pcall(function()
  202.         local data = ds:GetAsync(plr.UserId .. "Muted")
  203.         return data
  204.     end)
  205.    
  206.     if muteSuccess and muteData then
  207.         local muteEnd = muteData[1]
  208.        
  209.         if os.time() >= muteEnd then
  210.             pcall(function()
  211.                 ds:RemoveAsync(plr.UserId .. "Muted")
  212.             end)
  213.            
  214.         else
  215.             channel:MuteSpeaker(plr.Name)
  216.            
  217.             local timeToUnmute = muteEnd - os.time()
  218.             task.wait(timeToUnmute)
  219.            
  220.             if plr then
  221.                 channel:UnmuteSpeaker(plr.Name)
  222.             end
  223.         end
  224.     end
  225. end)
  226.  
  227.  
  228. --Receive global announcements
  229. local announcementConnection = ms:SubscribeAsync(announcementTopic, function(message)
  230.     if message and message.Data[1] then
  231.         re:FireAllClients("ANNOUNCE", message.Data[1])
  232.     end
  233. end)
  234. --Ban players across different servers
  235. local banConnection = ms:SubscribeAsync(banTopic, function(message)
  236.     local targetId = message.Data[1]
  237.     local banMessage = message.Data[2]
  238.    
  239.     for i, plr in pairs(game.Players:GetPlayers()) do
  240.         if plr.UserId == targetId then
  241.             plr:Kick(banMessage)
  242.         end
  243.     end
  244. end)
  245. --Mute players across different servers
  246. local muteConnection = ms:SubscribeAsync(muteTopic, function(message)
  247.     local targetId = message.Data[1]
  248.     local muteLength = message.Data[2]
  249.  
  250.     for i, plr in pairs(game.Players:GetPlayers()) do
  251.         if plr.UserId == targetId then
  252.            
  253.             channel:MuteSpeaker(plr.Name)
  254.  
  255.             task.wait(muteLength)
  256.             if plr then
  257.                 channel:UnmuteSpeaker(plr.Name)
  258.             end
  259.         end
  260.     end
  261. end)
  262. --Unmute players across different servers
  263. local unmuteConnection = ms:SubscribeAsync(unmuteTopic, function(message)
  264.     local targetId = message.Data[1]
  265.     for i, plr in pairs(game.Players:GetPlayers()) do
  266.         if plr.UserId == targetId then
  267.  
  268.             channel:UnmuteSpeaker(plr.Name)
  269.         end
  270.     end
  271. end)
  272. --Kick players across different servers
  273. local kickConnection = ms:SubscribeAsync(kickTopic, function(message)
  274.     local targetId = message.Data[1]
  275.     local kickReason = message.Data[2]
  276.     for i, plr in pairs(game.Players:GetPlayers()) do
  277.         if plr.UserId == targetId then
  278.  
  279.             plr:Kick(kickReason)
  280.         end
  281.     end
  282. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement