Argument 2 Missing or Nil

Hey, I’m making a ban system that uploads to a database online.

The database rows go as follows:
id, UserID (ID of the person who has been banned), BanStart, BanTime, Reason, ModUserID

The ban is placed into the database via a URL and it says argument 2 is missing or nil. I have pasted the code down below.

game.ReplicatedStorage.Event.Event:Connect(function(player, uid, banstart, bantime, reason)
-- Please note that the following prints do print out argument 2
	print(game.Players:GetUserIdFromNameAsync(player))
	print(game.Players:GetUserIdFromNameAsync(uid))
	print(banstart)
	print(bantime)
	print(reason)
	
	local muid = game.Players:GetUserIdFromNameAsync(player)
	local user = game.Players:GetUserIdFromNameAsync(uid)
	local bs = os.time()
	local bt = bantime
	local r = reason
	
	HttpService:PostAsync("https://[REDACTED]/create.php?ModUserID="..muid.."&UserID="..user.."&BanStart="..os.time().."&BanTime="..bt.."&Reason="..r.."")
	game.Players[uid]:Kick(r)
end)

I’m so confused because when the print commands run, it prints out the expected argument. Anybody know why this is happening?

The first argument for :PostAsync() is the destination address, the second argument is for the data to send.

1 Like
game.ReplicatedStorage.Event.Event:Connect(function(player, uid, banstart, bantime, reason)
-- Please note that the following prints do print out argument 2
	print(game.Players:GetUserIdFromNameAsync(player))
	print(game.Players:GetUserIdFromNameAsync(uid))
	print(banstart)
	print(bantime)
	print(reason)
	
	local muid = game.Players:GetUserIdFromNameAsync(player)
	local user = game.Players:GetUserIdFromNameAsync(uid)
	local bs = os.time()
	local bt = bantime
	local r = reason
	
	HttpService:PostAsync("https://[REDACTED]/create.php?ModUserID="..muid.."&UserID="..user.."&BanStart="..os.time().."&BanTime="..bt.."&Reason="..r..,"")
	game.Players[uid]:Kick(r)
end)```
1 Like

HttpService:PostAsync requires atleast 2 arguments with the 2nd being the data you are actually sending.
You are only providing the 1st argument which is the url you are sending the data to.
Also I hope that you use your external server exclusivly for data logging as your approach isn’t secure in any shape or form.

1 Like

Thank you, I know it’s not secure but I’m adding all security features to it after I’ve tested it to see if it works. Not my normal style of work but just testing it for now.

Doesn’t seem to be working. Can’t concatenate nil with string.

It is as it says. Make sure none of the variables you are concatenating are nil.

1 Like

Got it working now thank you. The data says its been sent but not going in the database, but that’s in php so I’ll get that fixed.

Ok, I used a different script as found here (HttpService | Roblox Creator Documentation).

I got it to print out the link that it posted to, and copied and pasted it into Chrome, which added the record to the database, however, it does not add the record when I use PostAsync().

which line is the error showing on?

1 Like

i believe post async is used for post requests and get requests, not going on php files.

1 Like

The php file grabs the data from the url using $_GET and adds it into the database. But Roblox sends the request and it says its been added, but it hasn’t. I’ll try different ways but not to worry if it doesn’t work.

1 Like

ah, thanks for the info, not experienced with php :frowning:

1 Like