EDIT: Please note this tutorial is quite dated, and may not work as expected. It is also recommended to not use as a database, unless for experimental/testing purposes.
decided to write this up around 3am in the morning, so excuse my weird grammar
So I thought I’d create a thread of an unusual way on how to record pretty much anything that you want to in your game such as players purchasing developer products, script errors, or even the chat history using HttpService.
The coolest thing about this is that it’s free, does not require any website hosting/setting up a database because it uses Google Docs (Google Sheets) so you can easily link your Google account and download, search and make record of whatever happens in-game! I don’t use HttpService currently for any other way and would like to get more into it, but I thought I’d share this if you want simple PostAsync stuff.
Now obviously this kind of use of the HttpService wasn’t exactly meant to be used like this as the submission is the url and not the data string. It’s better off for anything you want to store in forms or cells.
I’ll try to make this as easy as possible to understand for those who don’t really script but would like something like this in their place. Let’s assume you already have something that you want to use this for. Make sure to have the HttpService enabled in your place by going to ROBLOX Studio, click on the Model > Service > HttpService and put a checkmark on the HttpEnabled property. If you already have these properties set then you’re good!
Create a new Script (or better yet if you know how to use ModuleScripts you can go ahead and use that) and place it in the ServerScriptService or wherever fit for your projects.
Inside the script, copy and paste the following code in (or whatever variation you have in mind):
local hs = game:GetService("HttpService")
local hsEntry1 = ""
local hsEntry2 = ""
local hsKey = ""
local hsForm = ""
local hsHost = "https://docs.google.com/"
local function logSheet(var1, var2)
local hsLink = hsHost.."forms/d/"..hsForm.."/formResponse?entry."
..hsEntry1.."="..var1.."&submit=Submit&formkey="
..hsKey.."&entry."..hsEntry2.."="..var2.."&ifq"
-- Upload onto Google Sheets!
-- print(hsLink)
hs:PostAsync(hsLink, "", 2)
end
Now for the more complicated stuff. Go to the Google Sheets website https://docs.google.com/spreadsheets/ (or create a new one if you don’t yet) and create a new sheet. When a new one is generated for you the spreadsheet url be quite long, however there is a certain group of characters in that url which is the spreadsheet form. You want to copy that and paste it into the hsKey.
Now, in order to be able to post data you will need to create a new form for the spread sheet. It can be done by selecting Tools > Create a form
You will see that there is an Untitled Question with Option 1. You’ll want to change that from a Multiple choice to Text in Question Type when you edit the question. Let’s use the first entry for the player’s name.
Let’s add in a second entry. Let’s record player knockout/wipeouts as an example. Click on the Add Item button to add a new entry to the form and use a Text option.
Now that we have the 2 entries, we can select the send form button at the Confirmation Page section. Now while on the same page select the View live form button at the top.
You should have a submission form with the two entries you wrote. Now the URL of the submission form will have something similar to your spreadsheet, however it is not the same. Copy the alphanumeric characters after the /d/ until /viewform. This will be the hsForm. Next comes getting the submission entry numbers. It’s recommended that you have a browser that you can easily see the page source such as Google Chrome. Ctrl+F and search for ‘entry.’. There should be 2 results. They are your first and second entry keys for the Player Name and Player Killed. The first result will be the first entry and so forth. Be sure to get the numbers directly after entry. until the end of the number.
Once you have the form, key, and entries you can now start logging stuff in Google Sheets!
For an example, with the logSheet function, you can run it in a script and it will display on the Google sheet!
logSheet("Player1", "Player2") -- Can be replaced with any other variable to be manipulated as a string
Also, the Timestamp cell takes the date/time from the ROBLOX server so it may be under PST or CDT time zones. As far as I know, the limits to number of cells on Google Sheets is 2 million (I’m not sure if that’s not enough to cover whatever you’re doing) You can read more about it here: Files you can store in Google Drive - Google Drive Help
If you have any questions or comments about what this is still or want to tell me what I should actually be doing then feel free because I don’t really feel like having to get a server to host data unless you find one that’s free and for the purpose of keeping records then that would be nice.
Basically using Google Sheets as a Database. There’s some other pretty cool things I read about using it here: http://acrl.ala.org/techconnect/?p=4001