Ban System Help

Hey! I would like to make a ban system for my game, but I can’t seen to get it working. What I would like it to do, once a Game Mod/Admin sends the ban command (:ban [Player]) the player gets kicked from the game and there Roblox user id gets sent to a ban data store. If the banned player rejoins the game, then a ui shows for the player and there are teleported to a new place where they can appeal there ban.

I already have the ban appeal system working

Thanks!

2 Likes

Hey! Could you, like, actually tell us your problem? You didn’t say what your problem was, therefore no one can help you. Is your script not working, or do you just not know where to begin?

6 Likes

you would just put in the admin command functions a function that would simply put the banned player’s id into a key and a bool value as a value in a banland datastore. after doing that, kick the player. when a player joins, check their banland status and if true, then teleport them to a different place. simple.

4 Likes

I just don’t know where to start

2 Likes

If you are saving the banned user’s ID in a datastore, you just simply have to check to see if the user’s ID is in the datastore when he joins the server. Once you’ve found out if his ID is in the datastore, then you just do all your “GUI work.” You can either clone a screenGui and put it in the user’s PlayerGui, or you could use a RemoteEvent (or something of the sort) to “communicate” with a localscript. It should be pretty simple, as it seems you’ve already kind’ve got the idea.

4 Likes

Do you think you could help me make the script, I have no idea where to start the script

2 Likes

What part do you not quite understand how to do?

2 Likes

Check to see if the players user id is in the data store, how to send the user id to the dada store when the command is sent, and how to send the player to a new place

2 Likes

Could check like this (JUST AN EXAMPLE):

-- checking if they’re banned
local BANSTORE = DSS:GetGlobalDataStore(“BANSTORE”)
-- assuming if you want to share this data store with that other game you mentioned (where they are teleported if they’re banned)
game.Players.PlayerAdded:Connect(function(Player)
   Player.CharacterAdded:Connect(function(Character)
   pcall(function()
       if BANSTORE:GetAsync(Player.UserId) then
TPService:Teleport(info)
         end
      end)
     end)
end)
-- adding a player to the ban list
Player.Chatted:Connect(function(msg)
local targetedPlayer = game.Players:FindFirstChild(string.split(msg, “%s+”)[1]).Name
   if targetedPlayer and msg == `:ban {targetedPlayer}` then
 pcall(function()
   BANSTORE:SetAsync(userid, userid)
     end)
   end
end)
-- unbanning them
whatever you’re doing to unban them like a command or smthn then
pcall(function()
BANSTORE:RemoveAsync(userid)
   end)
end

Hopes this gives you some sort of y’know guide on like how you could go about doing this.

Also sorry for the terrible indentation lol, I did it on my phone manually.

3 Likes

Yeah, it’s not that hard, yet not that easy. However, this is a code I made really quickly. I haven’t tested it yet so I don’t know if it contains any errors. Anyways, this is the main point.

--// Settings \\ --
local DataStoreKey = "-nkmvfkmnjre899243"; -- Random string to save the data. Changing this will erase all previously saved data.
local GroupId = 1234567890; -- The ID of your Roblox group.
local MinAdminRank = 50; -- The ID of the minimum admin rank. Players with and above this rank will be considered admins.
local ReservedPlaceId = 0000000; -- The ID of your second place, where the players will be teleported.


-- // Services \\ --
local DataStoreService = game:GetService('DataStoreService');
local Players = game:GetService('Players');
local TeleportService = game:GetService('TeleportService');


--// DataStore \\ --
local BanDataStore = DataStoreService:GetDataStore('BansDataStore');


-- // Admin join \\ --
Players.PlayerAdded:Connect(function(Player)
	if Player:GetRankInGroup(GroupId) >= MinAdminRank then
		-- Player is an admin.
		Player.Chatted:Connect(function(Message)
			if Message.find(":ban") then
				-- This is a ban command.
				local PlayerUsername = Message:split(" ")[1];
				if not PlayerUsername then
					return warn("| Ban system error: player username wasn't found.");
				end
				if PlayerUsername:len() < 4 then
					 return warn("| Ban system error: player username was invalid (too short).");
				end
				
				-- First add the player ID to the datastore.
				local PlayerId;
				local Success, Error = pcall(function()
					PlayerId = Players:GetUserIdFromNameAsync(PlayerUsername);
				end)
				if not Success then
					return warn("| Ban system error: player ID wasn't found. Username: "..PlayerUsername..". Error: ", Error);
				end
				local Success, Error = pcall(function()
					BanDataStore:SetAsync(PlayerId..DataStoreKey, {true, Player.UserId, os.time()});
				end)
				if not Success then
					return warn("| Ban system error: Couldn't save ban to datastore. Username: "..PlayerUsername..". Error: ", Error);
				end
				
				local TargetPlayer;
				local Success, Error = pcall(function()
					TargetPlayer = Players:FindFirstChild(PlayerUsername);
				end)
				if not Success then
					return warn("| Ban system error: player instance wasn't found. Error: ", Error);
				end
				
				-- Now teleport the target player.
				local Success, Error = pcall(function()
					local ReservedServerCode = TeleportService:ReserveServer(ReservedPlaceId);
					if TargetPlayer then
						local Success, Error = pcall(function()
							TeleportService:TeleportToPrivateServer(ReservedPlaceId, ReservedServerCode, {TargetPlayer}, nil, nil);
						end)
						if not Success then
							return warn("| Ban system error: could not teleport player. Error: ", Error);
							
						else 
							print("| Ban system: player teleportation successful.");
						end
					else
						return warn("| Ban system error: player was missing while the teleportation was attempted.");
					end
				end)
			end
		end)
	end
	
	-- Check if player is banned.
	local SavedData;
	local Success, Error = pcall(function()
		SavedData = BanDataStore:GetAsync(Player.UserId..DataStoreKey);
	end)
	if not Success then
		return warn("| Ban system error: could not get data from datastore. Error: ", Error);
	end
	if SavedData then
		if SavedData[1] == true then
			print("| Ban system: ban detected for player "..Player.Name..". Ban issued by admin "..SavedData[2].." at "..SavedData[3]..".");
			-- Now teleport the target player.
			local TargetPlayer = Player;
			local Success, Error = pcall(function()
				local ReservedServerCode = TeleportService:ReserveServer(ReservedPlaceId);
				if TargetPlayer then
					local Success, Error = pcall(function()
						TeleportService:TeleportToPrivateServer(ReservedPlaceId, ReservedServerCode, {TargetPlayer}, nil, nil);
					end)
					if not Success then
						return warn("| Ban system error: could not teleport player. Error: ", Error);

					else 
						print("| Ban system: player teleportation successful.");
					end
				else
					return warn("| Ban system error: player was missing while the teleportation was attempted.");
				end
			end)
		end
	end
end)

Gotta mention Blueberry Plus if you’re looking for something already ready to use.

2 Likes