BanAsync() Not Working

I’m trying to set up an admin panel using the new ban API and it’s not working.

Here’s the first script (local)

script.Parent.MouseButton1Up:Connect(function()
	
	local PlayerName = script.Parent.Parent.PlayerName.Text
	local Message = script.Parent.Parent.Message.Text
	local Time = script.Parent.Parent.Time.Time.Value

	game.ReplicatedStorage.Misc.BanPlayer:FireServer(PlayerName, Message, Time)
end)

and the server side script:

game.ReplicatedStorage.Misc.BanPlayer.OnServerEvent:Connect(function(Player, Message, Time)
	game.Players:BanAsync({UserIds = {Player.UserId}, ApplyToUniverse = true, Duration = Time, DisplayReason = Message, PrivateReason = "Banned", ExcludeAltAccounts = false})
end)

I keep getting an error: “Config must contain field Duration with type number”

I tried many things such as tostring(), creating a number value and changing that to the inputted number, but still the same error. It only works when I directly enter the number into the function. (The way this is supposed to work is you enter the name, message and time and the player gets banned)

2 Likes

This could possibly be the wrong format, maybe try:
Time = tonumber(Time)

1 Like

idk if this is it, but when I use BanAsync, it says the service is not live. It could be something in game settings but I don’t know as I am unfamiliar with the ban API.

Edit: the type of the duration is the issue so try typechecking it to make sure it is a number:

if type(Time) ~= "number" then
      print("that is issue")
end

if this prints something, then the time value isnt a number and that would be what the issue is. Not sure how this would be wrong if you are using a numbervalue object (if you are using a stringvalue or something else change it to numbervalue), but that seems like the most likely issue.

1 Like

You’re it printed that there’s an issue. How would I make it work then?

1 Like

Ok, then make sure you have a numberValue object, or just store the duration as a value in the script. All that means is the Time variable has and incorrect type (Ex: it could be a boolean or smth).

1 Like

How would I do that LOL (sorry I’m kinda new to scripting)

1 Like

What I did ealier is I added a NumberValue into the script and made the value to text of the TextBox and took that number but it still didn’t work.

1 Like

Are you needing to change the ban length? Because if you dont it would be easier to just set the value inside the script:

Time = 1000

If you do, it would actually be easier to just send it to the function with events

1 Like

Make sure to not use tostring, that changes it to a string, which is not a number

I am changing the time. In the UI theres a box for time and that’s what needs to be sent through that won’t send for some reason.

Got it, so how is the function fired?

Edit: nvm im dumb

I’m just saying I tried that and I just left it as the Text of the TextBox itself.

I’m gonna check how the new API works in case they have an example of how to do it how I want.

1 Like

Oh i see, make sure you use tonumber when reading the text

I did and it still didn’t work.

script.Parent.MouseButton1Up:Connect(function()
	local PlayerName = script.Parent.Parent.PlayerName.Text
	local Message = script.Parent.Parent.Message.Text
	local Time = tonumber(script.Parent.Parent.Time.Text)

	game.ReplicatedStorage.Misc.BanPlayer:FireServer(PlayerName, Message, Time)
end)

On the documentation website it says the “ban duration” is an int value.

Only thing I can see that would he wrong is that it needs and integer, so maybe try rounding it to make sure its not a double or float

I don’t understand, would math.floor work?

Tes it would, but before you do that, you may be entering everything wrong. Don’t enter duration = time, just enter time. Maje sure you are doing that with all the other parameters too

In the server script or the local script?