Admin Panel Help #2

Right so, I need help with 2 things today both are about the ban system I am making on my admin panel.

#1 When I use the ban button it does not kick you, but if I leave and rejoin I’m banned. So I have to have it so when you push the ban button it also kicks you.

#2 I have no idea how to code the UnBan button, I know the end goal is to remove the UserId from the ban DataStore.

Heres the ban system code.
NOTE THE WHITELIST FOR THE ADMIN PANEL IS BUILT INTO THE BAN SERVER SCRIPT, DO NOT MIND THAT.

LocalScript. It fires the server

local button = script.Parent

button.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.Ban:FireServer(script.Parent.Parent.Parent.upper.Target.Text, script.Parent.Parent.Parent.upper.Reason.Text)
	script.Parent.Parent.Parent.upper.TextLabel.Text = "Player banned."
	script.Parent.Parent.Parent.upper.TextLabel.TextTransparency = 0
	wait(3)
	script.Parent.Parent.Parent.upper.TextLabel.Text = "Teleport failed, please try entering the username again."
	script.Parent.Parent.Parent.upper.TextLabel.TextTransparency = 1
end)

Heres the main server script with the built in whitelist.

local configModule = require(script.Admin.panel.Config)
local data = game:GetService("DataStoreService"):GetDataStore(configModule.DataStoreKey)
local configModule = require(script.Admin.panel.Config)
local admins = configModule.adminIDs

local BanMsg = "You have been permenantly banned from this game."

game.Players.PlayerAdded:Connect(function(player)
	for _, adminId in pairs(admins) do
		if player.UserId == adminId then
			local cloneUI = script.Admin:Clone()
			cloneUI.Parent = player.PlayerGui
			break
		end
	end
	local prevData = data:GetAsync(player.UserId)
	if prevData == nil then
		print("Player does not have to be banned!")
		prevData:SetAsync(player.UserId, false)
	elseif prevData == true then
		print("Player is banned.")
		player:Kick(BanMsg)
	end
end)

game.ReplicatedStorage.Ban.OnServerEvent:Connect(function(player, victim, reason)
	local found = game.Players:FindFirstChild(victim)
	
	if found then
		data:SetAsync(player.UserId, true) -- that inserts the player ban to DataStore
		found:Kick(data..' '..reason)
	end
end)

Please help, it would be very appreciated :heart:

Looking at the code, it should kick the player

you can get the userid of a player with the function
id = game:GetService('Players'):GetUserIdFromNameAsync(ThePlayerName)
you can either set the data to false or remove the data completely with
data:SetAsync(id, false)
or
data:RemoveAsync(id, false)

RemoveAsync needs only the key of the datastore record/entry to remove.

Hey!
I’m not the best at coding, could you walk me through it?
If not i wont blame you

https://developer.roblox.com/en-us/api-reference/function/GlobalDataStore/RemoveAsync

2 Likes

Right, so what I made only broke the ban sys. New additions at the bottom.

local configModule = require(script.Admin.panel.Config)
local data = game:GetService("DataStoreService"):GetDataStore(configModule.DataStoreKey)
local configModule = require(script.Admin.panel.Config)
local admins = configModule.adminIDs

local BanMsg = "You have been permenantly banned from this game."

game.Players.PlayerAdded:Connect(function(player)
	for _, adminId in pairs(admins) do
		if player.UserId == adminId then
			local cloneUI = script.Admin:Clone()
			cloneUI.Parent = player.PlayerGui
			break
		end
	end
	local prevData = data:GetAsync(player.UserId)
	if prevData == nil then
		print("Player does not have to be banned!")
		prevData:SetAsync(player.UserId, false)
	elseif prevData == true then
		print("Player is banned.")
		player:Kick(BanMsg)
	end
end)

game.ReplicatedStorage.Ban.OnServerEvent:Connect(function(player, victim, reason)
	local found = game.Players:FindFirstChild(victim)
	
	if found then
		data:SetAsync(player.UserId, true) -- that inserts the player ban to DataStore
		found:Kick(data..' '..reason)
	end
end)

game.ReplicatedStorage.UnBan.OnServerEvent:Connect(function(player, victim, reason)
	local found = game.Players:FindFirstChild(victim)

	if found then
		data:RemoveAsync(player.UserId, true) -- that inserts the player ban to DataStore
	end
end)

As @Forummer said, the RemoveAsync function only needs the key of the datastore entry so remove the true

		data:RemoveAsync(player.UserId) -- that inserts the player ban to DataStore

Alright, ill put that in the fired server function and see if it works.

yeah you are right. Thanks for the correction