Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 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
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local plrXP = ReplicatedStorage.RemoteEvents:WaitForChild("UpdatePlayerXP")
- local notifyPlr = ReplicatedStorage.RemoteEvents:WaitForChild("NotPlr")
- local OBlacklist = ReplicatedStorage.RemoteEvents:WaitForChild("OpenBlacklist")
- local DataStoreService = game:GetService("DataStoreService")
- local InfoStore = DataStoreService:GetDataStore("PlrXP")
- local BannedStore = DataStoreService:GetOrderedDataStore("Blacklist")
- -- Setting all variables for the Remotes and DataStores
- game:GetService("Players").PlayerAdded:Connect(function(plr)
- -- Setting basic variables for later use
- local plrid = plr.UserId
- local BannedUsers = {}
- local prefix = "!"
- -- Creating a hidden leaderstats and visible one just in case for future use
- local stats = Instance.new("Folder")
- stats.Name = "stats"
- stats.Parent = plr
- local leaderstats = Instance.new("Folder")
- leaderstats.Name = "leaderstats"
- leaderstats.Parent = plr
- -- Variables which will be used for XP and in game currency which will later on be loaded in from the datastore
- local sb = Instance.new("IntValue")
- sb.Name ="StrawBucks"
- sb.Parent = leaderstats
- local xp = Instance.new("IntValue")
- xp.Name ="XP"
- xp.Parent = stats
- local maxxp = Instance.new("IntValue")
- maxxp.Name ="MaxXP"
- maxxp.Value = 15
- maxxp.Parent = stats
- -- Debounce to check weather the user leveled up and his group rank has changed from the last time he was in the game
- local Lvlup = Instance.new("BoolValue")
- Lvlup.Name ="Lvldup"
- Lvlup.Parent = stats
- -- XP and Ingame currency + Debounce related loading
- local getSuccess, datatable = pcall(function()
- return InfoStore:GetAsync(plrid)
- end)
- if getSuccess then
- xp.Value = datatable[1]
- Lvlup.Value = datatable[2]
- sb.Value = datatable[3]
- else
- xp.Value = 0
- Lvlup.Value = false
- sb.Value = 0
- end
- -- FireAllClients so when a user joins everyones cash will be updated just in case
- game.ReplicatedStorage.RemoteEvents.MoneyUpdate:FireAllClients()
- -- Changing the MaxXp Value to a specific amount depending on the players current Role
- if plr:GetRankInGroup(11808630) == 201 then
- maxxp.Value = 15
- elseif plr:GetRankInGroup(11808630) == 202 then
- maxxp.Value = 30
- elseif plr:GetRankInGroup(11808630) == 203 then
- maxxp.Value = 50
- elseif plr:GetRankInGroup(11808630) > 203 then
- maxxp.Value = 50
- xp.Value = maxxp.Value
- end
- -- 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
- if Lvlup.Value == true and plr:GetRankInGroup(11808630) <= 203 then
- Lvlup.Value = false
- xp.Value = 0
- end
- --[[
- 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
- First it checks if the player using the commands is currently HR+
- --]]
- if plr:GetRankInGroup(11808630) >= 206 then
- -- Checks if the player chatted
- plr.Chatted:Connect(function(msg)
- local Ban
- local getSuccess, Banned = pcall(function()
- return BannedStore:GetAsync(plrid)
- end)
- if getSuccess then
- Ban = Banned
- end
- -- 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
- -- Lowers the message so it wont be case sensitive
- local loweredMsg = string.lower(msg)
- local args = string.split(loweredMsg, " ")
- -- If the player is either not banned or me/Handsum then they can continue with using the commands
- if not Ban or plr.Name == "Handsum" then
- --[[
- 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]
- 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
- Example of command : "!add Han 10"
- --]]
- if args[1] == prefix.."add" and args[3] ~= nil then
- -- Checks that the admin is going to add an amount over 0 else it notifies the admin by using robloxs SendNotification via remote
- if tonumber(args[3]) > 0 then
- -- 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
- for i,v in pairs(game:GetService("Players"):GetPlayers()) do
- if string.find(string.lower(v.Name), args[2]) then
- -- 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
- local XPPlayer = v
- -- Goes to the players stats/leaderstats in this case into their stats
- local XPPStats = XPPlayer.stats
- -- 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
- if XPPStats.XP.Value + args[3] >= XPPStats.MaxXP.Value then
- XPPStats.XP.Value = XPPStats.MaxXP.Value
- XPPStats.Lvldup.Value = true
- -- 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
- notifyPlr:FireClient(plr, "Added XP", args[3].."XP added to "..XPPlayer.Name ..", Player has leveled up.")
- else
- -- 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
- XPPStats.XP.Value += args[3]
- notifyPlr:FireClient(plr, "Added XP", args[3].."XP added to "..XPPlayer.Name)
- end
- -- Here it updates the player's GUI that has been given XP to so it correctly matches the amount they currently have
- plrXP:FireClient(XPPlayer, plr)
- end
- end
- else
- notifyPlr:FireClient(plr, "Invalid Amount", "XP amount adding to player must be above 0")
- end
- -- The remove command it basically the same as the add command so I do not see a reason to comment on it
- elseif args[1] == prefix.."remove" and args[3] ~= nil then
- if tonumber(args[3]) > 0 then
- for i,v in pairs(game:GetService("Players"):GetPlayers()) do
- if string.find(string.lower(v.Name), args[2]) then
- local XPPlayer = v
- local XPPStats = XPPlayer.stats
- if XPPStats.XP.Value - args[3] < 0 then
- XPPStats.XP.Value = 0
- else
- XPPStats.XP.Value -= args[3]
- end
- XPPStats.Lvldup.Value = false
- notifyPlr:FireClient(plr, "Removed XP", args[3].."XP removed from "..XPPlayer.Name)
- plrXP:FireClient(XPPlayer, plr)
- end
- end
- else
- notifyPlr:FireClient(plr, "Invalid Amount", "XP amount removing to player must be above 0")
- end
- --[[
- 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
- 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
- Example of command : "!blacklist Han"
- --]]
- elseif args[1] == prefix.."blacklist" and args[2] ~= nil and plr:GetRankInGroup(11808630) >= 211 then
- for i,v in pairs(game:GetService("Players"):GetPlayers()) do
- if string.find(string.lower(v.Name), args[2]) then
- --[[
- 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
- The BannedStore is then used at the beginning of this script when it is checking if player is banned
- --]]
- local success,err = pcall(function()
- return BannedStore:SetAsync(v.UserId, 1)
- end)
- if not success then
- warn("Failed: " .. err)
- end
- -- It will notify the player using the blacklist command that user specified can no longer user custom command
- notifyPlr:FireClient(plr, "Blacklist", v.Name.." can no longer custom commands")
- -- Now it will check 100 pages of the BannedStore/OrderedDatastore and it will fill a playerslist array with their key/UserID
- local pgs = BannedStore:GetSortedAsync(true, 100)
- local plrs = pgs:GetCurrentPage()
- local playerslist = {}
- for i, v in ipairs(plrs) do
- if v.value == 1 then
- table.insert(playerslist, v.key)
- end
- end
- -- After filling the playerlist it gets Fired with a RemoteEvent to update the blacklist just in case if the player has the blacklist open
- OBlacklist:FireClient(plr, playerslist, 0)
- break
- end
- end
- --[[
- 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
- This command is also available for Developer+ only and it checks whether args[2]/PlayerName has been filled.
- Example of command : "!whitelist Han"
- --]]
- elseif args[1] == prefix.."whitelist" and args[2] ~= nil and plr:GetRankInGroup(11808630) >= 211 then
- -- 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
- local pgs = BannedStore:GetSortedAsync(true, 100)
- local plrs = pgs:GetCurrentPage()
- for i,v in ipairs(plrs) do
- -- 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
- if args[2] == string.lower(game.Players:GetNameFromUserIdAsync(v.key)) then
- local success,err = pcall(function()
- return BannedStore:SetAsync(v.key, 0)
- end)
- if not success then
- warn("Failed: " .. err)
- end
- -- Afer whitelisting them it send a notification saying that the user can now use the custom commands again
- notifyPlr:FireClient(plr, "Whitelist", game.Players:GetNameFromUserIdAsync(v.key).." can use custom commands")
- break
- end
- end
- -- We get the playerlist array again and send it to the Blacklist to update it incase the player has it open
- local pgs = BannedStore:GetSortedAsync(true, 100)
- local plrs = pgs:GetCurrentPage()
- local playerslist = {}
- for i, v in ipairs(plrs) do
- if v.value == 1 then
- table.insert(playerslist, v.key)
- end
- end
- OBlacklist:FireClient(plr, playerslist, 0)
- --[[
- The next command is blacklist alone which means it has no argument after the command and it checks for that
- 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
- Example of command : "!blacklist"
- --]]
- elseif args[1] == prefix.."blacklist" and args[2] == nil and plr:GetRankInGroup(11808630) >= 211 then
- -- Gets all the players in the playerslist from the 100 pages of OrderedDataStore
- local pgs = BannedStore:GetSortedAsync(true, 100)
- local plrs = pgs:GetCurrentPage()
- local playerslist = {}
- for i, v in ipairs(plrs) do
- if v.value == 1 then
- table.insert(playerslist, v.key)
- end
- end
- -- 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
- OBlacklist:FireClient(plr, playerslist, 1)
- --[[
- And lastly this is the give command, this adds or removed in game currency to a specific player which is found by previous methods
- This is also a Developer+ only command and the command is used to add or remove currency
- Example of command : "!give Han 100" or if removing "!give Han -100"
- --]]
- elseif args[1] == prefix.."give" and args[2] ~= nil and plr:GetRankInGroup(11808630) >= 211 then
- for i,v in pairs(game:GetService("Players"):GetPlayers()) do
- if string.find(string.lower(v.Name), args[2]) then
- -- Once the player has been found he is set as a variable which is SBPlayer
- local SBPlayer = v
- -- 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
- local SBStats = SBPlayer.leaderstats
- SBStats.StrawBucks.Value += args[3]
- notifyPlr:FireClient(plr, "Added/Removed StrawBucks", args[3].." StrawBucks has been modified from "..SBPlayer.Name)
- end
- end
- else
- -- Else if the command used was none of these it will return as if nothing has ever happened
- return
- end
- end
- end)
- end
- -- When a player either has joined for the first time or resetted it will update their xp and everyones money just in case
- plr.CharacterAdded:Connect(function(char)
- repeat wait() until plr.Character:WaitForChild("Head")
- plrXP:FireClient(plr)
- game.ReplicatedStorage.RemoteEvents.MoneyUpdate:FireAllClients()
- end)
- end)
- -- The following function is used to save the xp, lvl and amount of money they have as an array into InfoStore
- local function SaveData(plr)
- local DataTable = {plr.stats.XP.Value, plr.stats.Lvldup.Value, plr.leaderstats.StrawBucks.Value}
- local success,err = pcall(function()
- return InfoStore:SetAsync(plr.UserId, DataTable)
- end)
- if not success then
- warn("Failed: " .. err)
- end
- end
- -- 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
- game:GetService("Players").PlayerRemoving:Connect(function(plr)
- SaveData(plr)
- end)
- game:BindToClose(function()
- for _, plr in pairs(game:GetService("Players"):GetPlayers()) do
- SaveData(plr)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement