What do you want to achieve?
I’m trying to make my own admin panel that others (mainly my friends) can use in their own games, if they HAVE their own games. Trying to figure out how to finish my ban command!
What is the issue?
When I press the button to fire the remoteEvent to the server, it just does nothing and it doesn’t return any errors for me. I don’t even know how to use BanAsync with the new Ban API!
What solutions have I tried to far?
I tried looking into the API but what I read was completely useless considering how I found shouldBeBanned() and getNextBanDuration() as two functions, not knowing what they did or meant.
Here is the LocalScript firing the event:
local button = script.Parent
local userBox = button.Parent:FindFirstChild("User")
local reasonBox = button.Parent:FindFirstChild("Reason")
local event = button:FindFirstChild("BanEvent")
-- Early exit if required UI elements are missing
if not button or not userBox or not event then
warn("BanClient: Missing required UI elements.")
return
end
local debounce = false
local cooldown = 1 -- seconds
button.MouseButton1Click:Connect(function()
if debounce then return end
debounce = true
local playerName = userBox.Text
local reason = reasonBox and reasonBox.Text or ""
event:FireServer(playerName, reason)
task.wait(cooldown)
debounce = false
end)
And here’s the code picking up the event
local button = script.Parent
local Event = button:FindFirstChild("BanEvent")
local Players = game:GetService("Players")
-- Early exit if required objects are missing
if not button or not Event then
warn("BanServer: Missing required objects.")
return
end
Event.OnServerEvent:Connect(function(sender, playerName, reason)
if typeof(playerName) ~= "string" or playerName == "" then
button.Text = "ERROR"
task.wait(1)
button.Text = "Ban"
return
end
local target = Players:FindFirstChild(playerName)
if target then
local success, err = pcall(function()
-- Ban permanently (duration = nil), or set duration in seconds if desired
local Players = game:GetService("Players")
if shouldBeBanned(sender) then
local banHistoryPages = Players:GetBanHistoryAsync(sender.UserId)
local duration = getNextBanDuration(banHistoryPages) -- Creator-implemented logic
local config: BanConfigType = {
UserIds = { sender.UserId },
Duration = duration,
DisplayReason = "You violated community guideline #5",
PrivateReason = "Put anything here that the user should not know but is helpful for your records",
ExcludeAltAccounts = false,
ApplyToUniverse = true,
}
local success, err = pcall(function()
return Players:BanAsync(config)
end)
print(success, err)
end
Players:BanAsync(target.UserId, nil, reason or "You have been banned from the server.")
end)
if success then
button.Text = "BANNED"
else
button.Text = "ERROR"
warn("BanServer: BanAsync failed -", err)
end
task.wait(1)
button.Text = "Ban"
else
button.Text = "ERROR"
task.wait(1)
button.Text = "Ban"
end
end)
I can’t figure out what’s going on, and how to use BanAsync correctly. Can someone help me with this issue and help me what shouldBeBanned() and getNextBanDuration() both mean and what the code is for them?
