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)
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
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.
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
}