Code after HttpService:PostAsync refuses to run

I am having one of the most indescribable errors that I’ve ever ran into. Well, not really, but here’s the issue that I’m experiencing…

Players.PlayerAdded:Connect(function(player)
	
	local result = "Some example text, obscured for security"
	
	local data = {
		["content"] = result
	}
	
	HttpService:PostAsync(endpointUrl, HttpService:JSONEncode(data), Enum.HttpContentType.ApplicationJson, false)
	
	player:Kick()
	
end)

Now, my issue is that, the code thereafter HttpService:PostAsync(endpointUrl, HttpService:JSONEncode(data), Enum.HttpContentType.ApplicationJson, false) is refusing to run! In this case, player:Kick(). But even calling print afterward is not working. Funny thing is, if I move the player:Kick() to the beginning of the callback, it works… no problems at all. Honestly, I have no idea why this is even happening. Wrapping PostAsync in a pcall does not help either. No errors… and I am receiving the message from PostAsync on my server. Super weird, does anybody know how to get this working?

2 Likes

Does kicking the player before the POST request not work for you? If it does, then you could probably keep it that way.

Another thing you could try is wrapping the POST request in a task.spawn, which will make it run on a separate thread.

2 Likes

I did think of this but I didn’t want to take this route as I wanted to figure it out, as something must’ve been wrong… I just figured it out, and stupidly enough, it’s because I did not close the Post request on my server. Thank you for your feedback!

3 Likes

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