Local playerToBan = Players:FindFirstChild(args) -search for player via specified playername in command Local duration = string.sub(message, string.find(message, numbers)) Local numbers = "%d" or "%d%d" - string pattern to look for duration/numbers
Local args = string.split(message, " ") -split string message via space, and iterate them into a table If string.sub(message, 1, #"/ban"):lower() = "/ban" then If plr.UserId = game.CreatorId then -restrict this command only to the owner Players.PlayerAdded:Connect(function(plr) If Result.BanStart + Result.BanDuration > os.time() then -see if ban duration has passed If Result then -see if ban data exists for the specified player or not If Success then -See if DataStore request was successful or not in order to prevent running into any errors Return BanStore:GetAsync(tostring(Player.UserId), "TempBan") Local Success, Error = pcall(function() -Protect the call in case the player specified doesn't exist, the player isn't found, or stuff like thatīanStore:SetAsync(tostring(Player.UserId), ) local function SetBan(Player, Reason, Duration) We’ll make sure to wrap this in a pcall in case we run into any errors that break the entire script, like the player not actually existing and all that good stuff. We’ll first want to start up with a function that sets the ban for the player. Now that we have the DataStore and the Players service, and we’ve created a new DataStore, we’ll then have to set up the functions for the ban before the main script, for better organization. While scopes are very optional, I’d prefer using them for better organization and usage in the feature, and for less confusion of the script. That is what we call a “Scope”, think of it as like a certain folder. "What is the number next to the "BanStore" string? Local BanStore = DDS:GetDataStore("BanStore", 2) -scope is optional Local Players = game:GetService("Players")
Local DDS = game:GetService("DataStoreService") We’ll start the script off by indexing/getting the DataStoreService and the Players service, which should be a fast and easy process. I’ll then be naming it jojo for better organization. I’m going to be making a server/general/regular/whatever script and putting it in ServerScriptService. With the reason being saved, so that the user sees it every time they attempt to enter the game while still banned. In this tutorial we’ll be making a custom ban command/ban system, of course. So without further ado, let’s get started. Today we’re going to be making your own simple ban system using Roblox’s built-in service DataStoreService. Now that you’ve (probably) read that, don’t expect this to be much of a versatile tutorial. Now before we start, this is my first ever post on the Community Tutorials category, and my first time making a tutorial as well, so sorry if it doesn’t make much sense, haha