Advertisement
yoyo74456

HireDevs.lua

Apr 20th, 2022
1,281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.66 KB | None | 0 0
  1. -- This is a script made by Handsum, this script takes care of all player loading and player leaving as well contains some custom commands which were made
  2.  
  3. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  4. local plrXP = ReplicatedStorage.RemoteEvents:WaitForChild("UpdatePlayerXP")
  5. local notifyPlr = ReplicatedStorage.RemoteEvents:WaitForChild("NotPlr")
  6. local OBlacklist = ReplicatedStorage.RemoteEvents:WaitForChild("OpenBlacklist")
  7. local DataStoreService = game:GetService("DataStoreService")
  8. local InfoStore = DataStoreService:GetDataStore("PlrXP")
  9. local BannedStore = DataStoreService:GetOrderedDataStore("Blacklist")
  10.  
  11. -- Setting all variables for the Remotes and DataStores
  12.  
  13. game:GetService("Players").PlayerAdded:Connect(function(plr)
  14.     -- Setting basic variables for later use
  15.     local plrid = plr.UserId
  16.     local BannedUsers = {}
  17.     local prefix = "!"
  18.    
  19.     -- Creating a hidden leaderstats and visible one just in case for future use
  20.     local stats = Instance.new("Folder")
  21.     stats.Name = "stats"
  22.     stats.Parent = plr
  23.    
  24.     local leaderstats = Instance.new("Folder")
  25.     leaderstats.Name = "leaderstats"
  26.     leaderstats.Parent = plr
  27.    
  28.     -- Variables which will be used for XP and in game currency which will later on be loaded in from the datastore
  29.     local sb = Instance.new("IntValue")
  30.     sb.Name ="StrawBucks"
  31.     sb.Parent = leaderstats
  32.    
  33.     local xp = Instance.new("IntValue")
  34.     xp.Name ="XP"
  35.     xp.Parent = stats
  36.    
  37.     local maxxp = Instance.new("IntValue")
  38.     maxxp.Name ="MaxXP"
  39.     maxxp.Value = 15
  40.     maxxp.Parent = stats
  41.    
  42.     -- Debounce to check weather the user leveled up and his group rank has changed from the last time he was in the game
  43.     local Lvlup = Instance.new("BoolValue")
  44.     Lvlup.Name ="Lvldup"
  45.     Lvlup.Parent = stats
  46.    
  47.     -- XP and Ingame currency + Debounce related loading
  48.     local getSuccess, datatable = pcall(function()
  49.         return InfoStore:GetAsync(plrid)
  50.     end)
  51.     if getSuccess then
  52.         xp.Value = datatable[1]
  53.         Lvlup.Value = datatable[2]
  54.         sb.Value = datatable[3]
  55.     else
  56.         xp.Value = 0
  57.         Lvlup.Value = false
  58.         sb.Value = 0
  59.     end
  60.    
  61.     -- FireAllClients so when a user joins everyones cash will be updated just in case
  62.     game.ReplicatedStorage.RemoteEvents.MoneyUpdate:FireAllClients()
  63.    
  64.     -- Changing the MaxXp Value to a specific amount depending on the players current Role
  65.     if plr:GetRankInGroup(11808630) == 201  then
  66.         maxxp.Value = 15
  67.     elseif plr:GetRankInGroup(11808630) == 202 then
  68.         maxxp.Value = 30
  69.     elseif plr:GetRankInGroup(11808630) == 203 then
  70.         maxxp.Value = 50
  71.     elseif plr:GetRankInGroup(11808630) > 203 then
  72.         maxxp.Value = 50
  73.         xp.Value = maxxp.Value
  74.     end
  75.    
  76.     -- If the player has joined and has leveled up from the last time he was here it checks and sets his xp back to 0 meaning the leveld up
  77.     if Lvlup.Value == true and plr:GetRankInGroup(11808630) <= 203 then
  78.         Lvlup.Value = false
  79.         xp.Value = 0
  80.     end
  81.    
  82.     --[[
  83.         Custom commands for the XP such as adding and removing xp, blacklist and whitelist from the custom commands for admin abuse and another commands to add money
  84.         First it checks if the player using the commands is currently HR+
  85.     --]]
  86.     if plr:GetRankInGroup(11808630) >= 206 then
  87.         -- Checks if the player chatted
  88.         plr.Chatted:Connect(function(msg)
  89.             local Ban
  90.             local getSuccess, Banned = pcall(function()
  91.                 return BannedStore:GetAsync(plrid)
  92.             end)
  93.            
  94.             if getSuccess then
  95.                 Ban = Banned
  96.             end
  97.  
  98.             -- Everytime someone HR+ talks it loads the ban list, just in case if they just blacklisted someone it updates instatly while they are in the blacklist window
  99.             -- Lowers the message so it wont be case sensitive
  100.             local loweredMsg = string.lower(msg)
  101.             local args = string.split(loweredMsg, " ")
  102.            
  103.             -- If the player is either not banned or me/Handsum then they can continue with using the commands
  104.             if not Ban or plr.Name == "Handsum" then
  105.                 --[[
  106.                     This first command will add XP to a specific player which will be args[2] in this case and add the specific amount of XP the admin has give, which will be args[3]
  107.                     First off it checks if the message has a Prefix which as set before is "!" and after the prefix it checks if it contains "add" which is this specific command, and it will only continue if the admin has given an amount of XP and is not set to nothing
  108.                     Example of command : "!add Han 10"
  109.                 --]]
  110.                 if args[1] == prefix.."add" and args[3] ~= nil then
  111.                     -- Checks that the admin is going to add an amount over 0 else it notifies the admin by using robloxs SendNotification via remote
  112.                     if tonumber(args[3]) > 0 then
  113.                         -- Searches through all the players and tried to find a player which has args[2] in it for example in the command "!add Han 10" it will get args[2] which is already lowered from before to "han" and use string.lower(v.Name) to lower everyones name and check using string.find() to see if there's anyone which has "han" in their name
  114.                         for i,v in pairs(game:GetService("Players"):GetPlayers()) do
  115.                             if string.find(string.lower(v.Name), args[2]) then
  116.                                 -- If a person was found then I set a variable which is XPPlayer to v which is the player that I am giving XP to
  117.                                 local XPPlayer = v
  118.                                 -- Goes to the players stats/leaderstats in this case into their stats
  119.                                 local XPPStats = XPPlayer.stats
  120.                                 -- Find the XP.Value and if after adding the XP it checks if goes over or reaches the Maximum amount of XP available then it will add the amount to the maximum amount of XP and it will set Lvldup to True which will be checked once the player joins back in the game
  121.                                 if XPPStats.XP.Value + args[3] >= XPPStats.MaxXP.Value then
  122.                                     XPPStats.XP.Value = XPPStats.MaxXP.Value
  123.                                     XPPStats.Lvldup.Value = true
  124.                                     -- After all that, the player giving the XP will be notified as before with roblox's SendNotification that the player has been given args[3] amount of XP and they've leveled up
  125.                                     notifyPlr:FireClient(plr, "Added XP", args[3].."XP added to "..XPPlayer.Name ..", Player has leveled up.")
  126.                                 else
  127.                                     -- If the XP given doesn't add up to or go over the maximum amount then it will just add the XP and Notify the player giving the XP that the command has worked
  128.                                     XPPStats.XP.Value += args[3]
  129.                                     notifyPlr:FireClient(plr, "Added XP", args[3].."XP added to "..XPPlayer.Name)
  130.                                 end
  131.                                 -- Here it updates the player's GUI that has been given XP to so it correctly matches the amount they currently have
  132.                                 plrXP:FireClient(XPPlayer, plr)
  133.                             end
  134.                         end
  135.                     else
  136.                         notifyPlr:FireClient(plr, "Invalid Amount", "XP amount adding to player must be above 0")
  137.                     end
  138.                     -- The remove command it basically the same as the add command so I do not see a reason to comment on it
  139.                 elseif args[1] == prefix.."remove" and args[3] ~= nil then
  140.                     if tonumber(args[3]) > 0 then
  141.                         for i,v in pairs(game:GetService("Players"):GetPlayers()) do
  142.                             if string.find(string.lower(v.Name), args[2]) then
  143.                                 local XPPlayer = v
  144.                                 local XPPStats = XPPlayer.stats
  145.                                 if XPPStats.XP.Value - args[3] < 0 then
  146.                                     XPPStats.XP.Value = 0
  147.                                 else
  148.                                     XPPStats.XP.Value -= args[3]
  149.                                 end
  150.                                 XPPStats.Lvldup.Value = false
  151.                                
  152.                                 notifyPlr:FireClient(plr, "Removed XP", args[3].."XP removed from "..XPPlayer.Name)
  153.                                 plrXP:FireClient(XPPlayer, plr)
  154.                             end
  155.                         end
  156.                     else
  157.                         notifyPlr:FireClient(plr, "Invalid Amount", "XP amount removing to player must be above 0")
  158.                     end
  159.                     --[[
  160.                         In this upcoming command is the blacklist command, it features most of the previous commands statements/loops such as the for loop checking for the players and the if statement which checks for the player
  161.                         but this command is only available for Developer+, this command checks whether the args[2] which is player name is nil because if it was then the command has a different functionality
  162.                         Example of command : "!blacklist Han"
  163.                     --]]
  164.                 elseif args[1] == prefix.."blacklist" and args[2] ~= nil and plr:GetRankInGroup(11808630) >= 211 then
  165.                     for i,v in pairs(game:GetService("Players"):GetPlayers()) do
  166.                         if string.find(string.lower(v.Name), args[2]) then
  167.                             --[[
  168.                                 After the user has been found using previous methods it goes into BannedStore which is a datastore containing previously banned robloxians ids and sets their value to 1 meaning that the person is banned
  169.                                 The BannedStore is then used at the beginning of this script when it is checking if player is banned
  170.                             --]]
  171.                             local success,err = pcall(function()
  172.                                 return BannedStore:SetAsync(v.UserId, 1)
  173.                             end)
  174.  
  175.                             if not success then
  176.                                 warn("Failed: " .. err)
  177.                             end
  178.                            
  179.                             -- It will notify the player using the blacklist command that user specified can no longer user custom command
  180.                             notifyPlr:FireClient(plr, "Blacklist", v.Name.." can no longer custom commands")
  181.                            
  182.                             -- Now it will check 100 pages of the BannedStore/OrderedDatastore and it will fill a playerslist array with their key/UserID
  183.                             local pgs  = BannedStore:GetSortedAsync(true, 100)
  184.                             local plrs = pgs:GetCurrentPage()
  185.  
  186.                             local playerslist = {}
  187.                             for i, v in ipairs(plrs) do
  188.                                 if v.value == 1 then
  189.                                     table.insert(playerslist, v.key)
  190.                                 end
  191.                             end
  192.                             -- After filling the playerlist it gets Fired with a RemoteEvent to update the blacklist just in case if the player has the blacklist open
  193.                             OBlacklist:FireClient(plr, playerslist, 0)
  194.                             break
  195.                         end
  196.                     end
  197.                     --[[
  198.                         In this upcoming command is the whitelist command, This command contains most of the code that there is in the blacklist but modified a bit
  199.                         This command is also available for Developer+ only and it checks whether args[2]/PlayerName has been filled.
  200.                         Example of command : "!whitelist Han"
  201.                     --]]
  202.                 elseif args[1] == prefix.."whitelist" and args[2] ~= nil and plr:GetRankInGroup(11808630) >= 211 then
  203.                     -- This command goes through the 100 pages of OrderedDataStore instead of the player list, because an admin might want to whitelist someone who is not currently in their game
  204.                     local pgs  = BannedStore:GetSortedAsync(true, 100)
  205.                     local plrs = pgs:GetCurrentPage()
  206.                    
  207.                     for i,v in ipairs(plrs) do
  208.                         -- It checks the page of players and if it finds someone which contains args[2] using GetNameFromUserIdAsync() as that is what I saved them as in the OrderedDataStore then it sets their value as 0, meaning whitelisted
  209.                         if args[2] == string.lower(game.Players:GetNameFromUserIdAsync(v.key)) then
  210.                             local success,err = pcall(function()
  211.                                 return BannedStore:SetAsync(v.key, 0)
  212.                             end)
  213.  
  214.                             if not success then
  215.                                 warn("Failed: " .. err)
  216.                             end
  217.                             -- Afer whitelisting them it send a notification saying that the user can now use the custom commands again
  218.                             notifyPlr:FireClient(plr, "Whitelist", game.Players:GetNameFromUserIdAsync(v.key).." can use custom commands")
  219.                             break
  220.                         end
  221.                     end
  222.                    
  223.                     -- We get the playerlist array again and send it to the Blacklist to update it incase the player has it open
  224.                     local pgs  = BannedStore:GetSortedAsync(true, 100)
  225.                     local plrs = pgs:GetCurrentPage()
  226.  
  227.                     local playerslist = {}
  228.                     for i, v in ipairs(plrs) do
  229.                         if v.value == 1 then
  230.                             table.insert(playerslist, v.key)
  231.                         end
  232.                     end
  233.                     OBlacklist:FireClient(plr, playerslist, 0)
  234.                     --[[
  235.                         The next command is blacklist alone which means it has no argument after the command and it checks for that
  236.                         This command is also available for Developer+ only and it opens a GUI containing all the players which are blacklisted getting their headshots/names using the UserID
  237.                         Example of command : "!blacklist"
  238.                     --]]
  239.                 elseif args[1] == prefix.."blacklist" and args[2] == nil and plr:GetRankInGroup(11808630) >= 211 then
  240.                     -- Gets all the players in the playerslist from the 100 pages of OrderedDataStore
  241.                     local pgs  = BannedStore:GetSortedAsync(true, 100)
  242.                     local plrs = pgs:GetCurrentPage()
  243.                    
  244.                     local playerslist = {}
  245.                     for i, v in ipairs(plrs) do
  246.                         if v.value == 1 then
  247.                             table.insert(playerslist, v.key)
  248.                         end
  249.                     end
  250.                     -- Fires to the client the playerlist along side with a numeric number which will be used as a boolean instead to check if it is being opened
  251.                     OBlacklist:FireClient(plr, playerslist, 1)
  252.                     --[[
  253.                         And lastly this is the give command, this adds or removed in game currency to a specific player which is found by previous methods
  254.                         This is also a Developer+ only command and the command is used to add or remove currency
  255.                         Example of command : "!give Han 100" or if removing "!give Han -100"
  256.                     --]]
  257.                 elseif args[1] == prefix.."give" and args[2] ~= nil and plr:GetRankInGroup(11808630) >= 211 then
  258.                     for i,v in pairs(game:GetService("Players"):GetPlayers()) do
  259.                         if string.find(string.lower(v.Name), args[2]) then
  260.                             -- Once the player has been found he is set as a variable which is SBPlayer
  261.                             local SBPlayer = v
  262.                             -- And his stats are found which in this case are in their leaderstats folder, it will add/remove the amount specified which is in args[3] and notify the user using the command of his actions
  263.                             local SBStats = SBPlayer.leaderstats
  264.                             SBStats.StrawBucks.Value += args[3]
  265.                             notifyPlr:FireClient(plr, "Added/Removed StrawBucks", args[3].." StrawBucks has been modified from "..SBPlayer.Name)
  266.                         end
  267.                     end
  268.                 else
  269.                     -- Else if the command used was none of these it will return as if nothing has ever happened
  270.                     return
  271.                 end
  272.             end
  273.         end)
  274.     end
  275.    
  276.     -- When a player either has joined for the first time or resetted it will update their xp and everyones money just in case
  277.     plr.CharacterAdded:Connect(function(char)
  278.         repeat wait() until plr.Character:WaitForChild("Head")
  279.         plrXP:FireClient(plr)
  280.         game.ReplicatedStorage.RemoteEvents.MoneyUpdate:FireAllClients()
  281.     end)
  282. end)
  283.  
  284. -- The following function is used to save the xp, lvl and amount of money they have as an array into InfoStore
  285. local function SaveData(plr)
  286.     local DataTable = {plr.stats.XP.Value, plr.stats.Lvldup.Value, plr.leaderstats.StrawBucks.Value}
  287.     local success,err = pcall(function()
  288.         return InfoStore:SetAsync(plr.UserId, DataTable)
  289.     end)
  290.  
  291.     if not success then
  292.         warn("Failed: " .. err)
  293.     end
  294. end
  295.  
  296. -- This makes sure that when the player is being removed from the game it fires the above function and just to be safe I also binded the function to when the player is closing the game
  297. game:GetService("Players").PlayerRemoving:Connect(function(plr)
  298.     SaveData(plr)
  299. end)
  300.  
  301. game:BindToClose(function()
  302.     for _, plr in pairs(game:GetService("Players"):GetPlayers()) do
  303.         SaveData(plr)
  304.     end
  305. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement