Help with a ban/unban ui button

Hey, I’m pretty new to scripting but I’m making an admin panel at the moment and it needs a ban/unban button. I’ve never used Data Stores before in my life so if anyone could help that would be awesome, thanks.

10 Likes

You can use an open-source ban script. Then you can just use:

BanModule.Ban("Coolrabbitsaregreen")

Alternatively, if you want to implement it yourself then look at the official data stores tutorial. If you get stuck, post your code for review.

6 Likes

wow! thank you very much! this will be extremely useful for my admin panel!

4 Likes

uh, the script isn’t working it comes up with an error that says:

function CheckPlr(partialuser)
	for _,v in pairs(game.Players:GetPlayers()) do
		if v.Name:lower():sub(1,#partialuser) == partialuser:lower() or v.DisplayName:lower():sub(1,#partialuser) == partialuser:lower() then
			return v.Name
		end
	end
end

local BanIt = require(6451678459)
local event = script.Parent.BanEvent

event.OnServerEvent:Connect(function(plr, name)
	local foundplayer = game.Players:FindFirstChild(CheckPlr(name))
	if foundplayer then
		BanIt.Ban(foundplayer)
	end
end)
3 Likes

That’s because you are passing the player Instance instead of its name. Here’s the script updated:

function CheckPlr(partialuser)
	for _,v in pairs(game.Players:GetPlayers()) do
		if v.Name:lower():sub(1,#partialuser) == partialuser:lower() or v.DisplayName:lower():sub(1,#partialuser) == partialuser:lower() then
			return v.Name
		end
	end
end

local BanIt = require(6451678459)
local event = script.Parent.BanEvent

event.OnServerEvent:Connect(function(plr, name)
	local foundplayer = game.Players:FindFirstChild(CheckPlr(name))
	if foundplayer then
		BanIt.Ban(foundplayer.Name)
	end
end)
3 Likes

oh shoot, thanks very much, let me test that

2 Likes

ugh another error and I have no idea what it means…

local button = script.Parent
local textbox = script.Parent.Parent.CMDBAR
local event = script.Parent.BanEvent

button.MouseButton1Click:Connect(function()
	local name = textbox.Text
	event:FireServer(name)
	script.kicksound:Play()
end)
2 Likes

Show me only line 3. Not sure why that might happen.

2 Likes
local event = script.Parent.BanEvent

image

2 Likes

Hi, for questions like due you can ask next time now the new ai of roblox which you find on the doc page. She can help you but also program it for you. She also answers faster than we. If you still have questions, then ask here.
(The AI is really good!)

2 Likes

what ai? the beta ai? I tried it before but a lot of the time it doesn’t work too well.

1 Like

Yes, the new one on the doc page. I am sure it can help you for this problem. Interesting, it always works for me 98%

2 Likes

alright I’ll try it out right now

1 Like

So, her response:

local DataStoreService = game:GetService("DataStoreService")
local banDataStore = DataStoreService:GetDataStore("BanDataStore")

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BanEvent = Instance.new("RemoteEvent")
BanEvent.Name = "BanEvent"
BanEvent.Parent = ReplicatedStorage

local UnbanEvent = Instance.new("RemoteEvent")
UnbanEvent.Name = "UnbanEvent"
UnbanEvent.Parent = ReplicatedStorage

function banPlayer(player, userId)
    banDataStore:SetAsync(tostring(userId), true)
end

function unbanPlayer(player, userId)
    banDataStore:RemoveAsync(tostring(userId))
end

BanEvent.OnServerEvent:Connect(banPlayer)
UnbanEvent.OnServerEvent:Connect(unbanPlayer)

game.Players.PlayerAdded:Connect(function(player)
    local userId = player.UserId
    local isBanned, error = pcall(function()
        return banDataStore:GetAsync(tostring(userId))
    end)
    
    if isBanned then
        player:Kick("You are banned from this game.")
    end
end)

[…]
You only need a local script. NOTE THAT THE AI RESPONSE IS NOT SECURE. BUT YOU CAN ASK HER FOR A SECURER VERSION.

2 Likes

I got the ban part working but I didn’t get the unban thing working it says arguement 1 missing or nil

1 Like

That’s very complicated and overdone for no reason.

local script? for datastores?

function CheckPlr(partialuser)
	for _,v in pairs(game.Players:GetPlayers()) do
		if v.Name:lower():sub(1,#partialuser) == partialuser:lower() or v.DisplayName:lower():sub(1,#partialuser) == partialuser:lower() then
			return v
		end
	end
end

local BanIt = require(6451678459)
local event = script.Parent.BanEvent

event.OnServerEvent:Connect(function(plr, name)
	local foundplayer = CheckPlr(name)
	if foundplayer then
		BanIt.Ban(foundplayer)
	end
end)
1 Like


image

1 Like

I banned my alt but idk how to unban them since when they join it kicks them so I can’t unban them

1 Like

dont use that, just use the standalone function, it should return their player instance instead of name
local foundplayer = CheckPlr(name)

2 Likes

Context. Don’t just pick out statements. To call that when a button is clicked. The main script is as you can see from the components a server script

2 Likes