(ROUND 2) i always get this error code when i try banning myself

well i did the same post a few hours ago but the bug dosent seem to be fixed
im a developer of a game and im trying to make a ban ui but it seems to not work
Local Script:

local button = script.Parent
local user = script.Parent.Parent.TextBox
local userreason = script.Parent.Parent.TextReason

button.MouseButton1Click:Connect(function()
	game.ReplicatedStorage["Banny_Binny!"]:FireServer(user.Text, userreason.Text)
	user.Text = "Player Succesfully BANNED"
	userreason.Text = "Reason"
	task.wait(1)
	user.Text = "username"
end)

Normal 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)
	if not table.find(AllowedPeople, player.UserId) then return end
	local plr = ps:FindFirstChild(bannedplr)
	local config: BanConfigType = {
		UserIds = ps:GetUserIdFromNameAsync(plr), -- couldnt get this to a pcall statement :()
		Duration =tonumber(player:WaitForChild("PlayerGui").Admn.Frame.TextDurationSeconds.Text) or convertHoursIntoSecends(tonumber(player:WaitForChild("PlayerGui").Admn.Frame.TextDurationHours.Text)) or convertDaysToSecends(tonumber(player:WaitForChild("PlayerGui").Admn.Frame.TextDurationDays.Text)),
		DisplayReason = banrsn,
		PrivateReason = "This Player Got Banned Because of:"..banrsn
	}

	local success, errorMessage = pcall(function()
		return ps:BanAsync(config)
	end)
	if success then
		print("THE ALMIGHTY BAN CAME")
	else
		warn("i no no wanna ban")
	end
end)

and heres the error code

and the spot of the error code:

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

(sorry if i put too much detail i just want to fix it)

Whatever you’re passing into convertHoursIntoSecends is being converted to nil, probably by tonumber which returns nil if the passed argument can’t be parsed into a number.

Duration =tonumber(player:WaitForChild("PlayerGui").Admn.Frame.TextDurationSeconds.Text) or convertHoursIntoSecends(tonumber(player:WaitForChild("PlayerGui").Admn.Frame.TextDurationHours.Text)) or convertDaysToSecends(tonumber(player:WaitForChild("PlayerGui").Admn.Frame.TextDurationDays.Text)),

I think you should split this line up into multiple lines. It’s a bit difficult to read what’s going on here.

tonumber(player:WaitForChild("PlayerGui").Admn.Frame.TextDurationHours.Text)

Can you confirm that is actually returning a number and not nil?

did i do it right because when you said switch it to that i thought you mean to remove duration am i right?

Yea, it’s right. I was just making a suggestion. You should confirm that player:WaitForChild("PlayerGui").Admn.Frame.TextDurationHours.Text is being converted to a number properly though.

1 Like

alright it works but its giving me this its not an error code but this

Screenshot 2024-10-16 020008

because of this line:

	if success then
		print("THE ALMIGHTY BAN CAME")
	else
		warn("i no no wanna ban")
	end
end)

errorMessage should tell you why the pcall failed. You should print that as well

i see why.

Screenshot 2024-10-16 020339

Take a look at the documentation for BanAsync. It explains how config should look and it gives an example

thanks alot.
might aswell put the solution since it probbably got fixed

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