(SOLVED) BanASync() Shows that it Works But Dosent

Hello guys.

I’m doing a ban ui but it prints the success message but dosent do anything

heres the script:

local ps = game:GetService("Players")


function convertDaysToSecends(days)
	return 86400 * tonumber(days)
end


function convertHoursIntoSecends(hours)
	return 3600 * tonumber(hours)
end

local AllowedPeople = {
	1813216757,
	1915724787,
	1029123331,
	2728185622,
}



game.ReplicatedStorage["Banny_Binny!"].OnServerEvent:Connect(function(player, bannedplr, banrsn, bandur)
	if not table.find(AllowedPeople, player.UserId) then return end
	print(tonumber(bandur))
	local config: BanConfigType = {
		UserIds = {bannedplr.UserId},
		Duration = tonumber(bandur),
		DisplayReason = banrsn,
		PrivateReason = bannedplr.." Got Banned Because of:"..banrsn
	}

	local success, errorMessage = pcall(function()
		return ps:BanAsync(config)
	end)
	if success then
		print(success) -- this is what it prints but dosent actually ban the player
	else
		warn(errorMessage)
	end
end)

Are you testing in Studio? Requests won’t work in studio, you can see a little blue message indicating this in the output:

BanAsync will succeed on game production servers. Skipping request in test environment...

Oh its you again

anyways ill try testing it in game

yes its me again :>

be careful testing in-game if you ban yourself you can go to creator dashboard → your game → moderation → bans to unban yourself since UnbanAsync won’t work in studio either

i update the game and tested it but it still didnt ban me

did you get any errors? did the success message output?

try printing config (note you will need to print it like this:

for i, v in config do
    print(i, v)
end

and seeing if its correct

I did and it gave me this:

Screenshot 2024-10-16 175437

ok so the user id is coming out as nil. It looks like bannedplr is a Player, and you can’t pass instances along remote events. Try passing just their UserId and Name along in a table.

remote:FireServer({Name = bannedplr.Name, UserId = bannedplr.UserId, banrsn, bandur)

you’re also trying to concatenate the player here which won’t work, do bannedplr.Name

didnt understand what you meant by

since where do i place it

in your script that fires the remote

if you send the code snippet that fires the remote I’ll show you where

heres the local script that fires the remote event:

local button = script.Parent
local user = script.Parent.Parent.TextBox
local userreason = script.Parent.Parent.TextReason
local duration = script.Parent.Parent.TextDurationHours
button.MouseButton1Click:Connect(function()
	game.ReplicatedStorage["Banny_Binny!"]:FireServer(user.Text, userreason.Text, duration.Text)
	user.PlaceholderText = "Player Succesfully BANNED"
	userreason.PlaceholderText = "Reason"
	user.Text = ""
	userreason.Text = ""
	task.wait(1)
	user.PlaceholderText = "username"
end)

Ok. So, here, you are passing the name of the player.

On the server, bannedplr will be a string - the name of the player you want to ban. When you try to index UserId, it comes out as nil. It doesn’t error because strings have some functions that can be indexed. So, you are assigning it to:

UserIds = {nil}

which is why it doesn’t work. To fix this, you can change your server-sided function:

--replacing config part
bannedplr = ps:FindFirstChild(bannedplr)
if not bannedplr then warn("no player!") return nil end
local config: BanConfigType = {
    UserIds = {bannedplr.UserId},
    Duration = tonumber(bandur),
    DisplayReason = banrsn,
    PrivateReason = bannedplr.Name.." got banned because of: "..banrsn,
    --adding these two fields to make sure they "properly" get banned
    ExcludeAltAccounts = false,
    ApplyToUniverse = true
}
1 Like

AYY MAN TYSM IT FINALLY WORKS NOW :slightly_smiling_face:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.