Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Message someone from my game?

Asked by
1x5x2 0
8 years ago

How do I use the HttpService to send data to a site that Messages someone with the information given in the script?

Yes. HttpEnabled is true.

1 answer

Log in to vote
1
Answered by 8 years ago

Well, to do the messaging part, you would require a rather open knowledge of PHP. To do the data send, we must use HttpService. Before we can use this, we must tell the script that we are going to be using HttpService.

local http = game:GetService("HttpService")

Now that we have told the script what HttpService is, we now must start writing some variables. This part is very important, so pay close attention. The first variables we define will be the URL of the website you're sending data to, and the data itself Lets say the url is this very question at ScriptingHelpers.org! We would do the following:

local url = "http://www.scriptinghelpers.org/questions/21865/message-someone-from-my-game"
local data = "Hi"

Now you might be wondering, "Why did we put the data in a variable?" We put the data in a variable because now we will be using the function JSONEncode. What this does is it makes it so the website can actually read what you're sending it. To use this, you would do this:

data = http:JSONEncode(data)

And now, finally, after all that preparation, we must send the data to the website. To achieve this, we must use a Yield function entitled PostAsync. To use PostAsync with this, you would do the following:

http:PostAsync(url, data)

After all of this, your code should look something similar to:

local http = game:GetService("HttpService")
local url = "http://www.scriptinghelpers.org/questions/21865/message-someone-from-my-game"
local data = "Hi"
data = http:JSONEncode(data)
http:PostAsync(url, data)
print(data) -- Prints the data you sent so you can check if its valid.

For more information, watch this video from CodeTheorem: https://www.youtube.com/watch?v=4u4pq_8muck or visit this roblox wiki page: http://wiki.roblox.com/index.php?title=Sending_HTTP_requests

Ad

Answer this question