(UNSOLVABLE.) Attempt to perform arithmetic (mul) on number and nil

hello everyone
today i was making a ban ui for a game i had been working on
and it shows me this error code

heres the code:

local ps = game:GetService("Players")


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


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




game.ReplicatedStorage["Banny_Binny!"].OnServerEvent:Connect(function(player, bannedplr, banrsn)
	local plr = ps:FindFirstChild(bannedplr)
	local config: BanConfigType = {
		UserIds = ps:GetUserIdFromNameAsync(plr),
		Duration =tonumber(player.PlayerGui.Admn.Frame.TextDurationSeconds.Text) or convertHoursIntoSecends(tonumber(player.PlayerGui.Admn.Frame.TextDurationHours.Text)) or convertDaysToSecends(tonumber(player.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)

any help would be great

(also this is my first post)

2 Likes

if this isn’t assigned to on the server, it’ll be viewed as what you set it to before, likely the value it has in StarterGui… so probably nil. You need to get the correct value on the server for the multiplication to work.

2 Likes

i mean the error code was at

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

so i dont know if its the solution

2 Likes

You’re passing the text as a parameter to that, which is causing your issue - the server is viewing it as nil because when the client updates it it doesn’t replicate. Try sending it to the server from the client and using that value.

2 Likes

alright now it works but theres another error code appearing

Screenshot 2024-10-15 231553

2 Likes

Admn is nil here. Make sure you got that path right.

You also have a few vulnerabilities.

  • No sanity checks means anyone can fire the remotes to ban players, not just admins.
  • Players:GetUserIdFromNameAsync can fail, use a pcall and error handling.
2 Likes
  • No sanity checks means anyone can fire the remotes to ban players, not just admins.

well thats why im making ban system. duh :stuck_out_tongue_closed_eyes:
jokes aside ill try implementing it. issue is. im an intermediate developer and trying to work for a game

2 Likes

you do understand what i meant, right…? Exploiters can just ban anyone from your game by firing the remote?

2 Likes

i know thats why i said ill try implementing it

2 Likes

yeah but you also said this in response

so i just wanted to make sure

2 Likes

it was just a joke sir alright?

2 Likes

heres the script so far

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) 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)
2 Likes

i get it was a joke but you said “thats why im making a ban system duh” in response to “hackers can just fire the remotes” which i dont really understand how it makes sense. It sounded to me like you didn’t get that other people could fire the remote.

I give up… XD

anyway

that should be

if not table.find(AllowedPeople, player.UserId) then return end
2 Likes

gonna put this as a solution since it basically got rid of the error code XD

3 Likes

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