Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Intergration

Reece Harris edited this page Jul 9, 2021 · 5 revisions

DataStore3 is a modular system to easily use 3rd part databases, This is a guide on how to setup and use DataStore3 now!


Setting up the library file

  • Once you have installed the DataStore3 plugin Head over to Roblox Studio
  • Go to the Plugins tab at the top of Roblox Studio, Click on the button called Summon DataStore3Libary
  • A window should open (If the text is shrunk or stretched resize the window) now fill out your server details.
    Hostname - The server IP (Public IP) and the port you used to port forward.
    Username - The username you used to access the database (Not your Roblox username)
    Api Key - The API key you generated (How to generate a key)
  • Now click the submit button, Well done you have finished setting up DataStore3 now the best part, writing your code!

Creating your script

  • Create a new script inside ServerScriptService
  • Import DataStore3Libary by putting this at the top
local DataStore3 = require(game:GetService("ServerScriptService").DataStore3Libary);

This allows you to use the built-in functions allowing you to interact with your server.

  • Now it's your turn to use DataStore3 to its full potential

Syntax

DataStore3.PostPayload(payload)

  • arguments - payload

payload The SQL payload that is sent to the server.

  • Example

Auto save data every 30 seconds, In this example we save gold, gems and wood this isn't hard coded meaning you can make this anything and as many as you want

local DataStore3 = require(game:GetService("ServerScriptService").DataStore3Libary);  --Imports the DataStore3 libary

local Players = game:GetService("Players")

while true do  -- Infinate Loop
	for i,v in pairs(game.Players:GetChildren()) do    -- Get all active players in game
		gold = v.leaderstats.Gold.Value   -- Get players Gold Value
		gems = v.leaderstats.Gems.Value   -- Get players Gems Value
		wood = v.Inventory.Wood.Value     -- Get players Wood Value

                -- Update table called userData and set gold, wood and gems where usersId = players user id
		local payload = "UPDATE userData SET gold ='"..gold.."', wood ='"..wood.."', gems='"..gems.."' WHERE userId = '"..v.UserId.."';" 
		local response = DataStore3.PostPayload(payload)  -- Send the Post request to the server
	end
	wait(30)  -- Wait 30 seconds to loop again
end

DataStore3.GetPayload(payload)

  • arguments - payload

payload The SQL payload that is sent to the server.

  • Example

Gets all data from a database for a user using there UserId and save the response as response

local DataStore3 = require(game:GetService("ServerScriptService").DataStore3Libary);  --Imports the DataStore3 libary

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)  -- Player Join function
	local userid = player.UserId          -- Get UserId of joined player
	local payload = "SELECT * FROM userData WHERE userId ='"..userid.."'"   -- Select all from userdata table where userId = players userid (SQL CODE)
	local response = DataStore3.GetPayload(payload)                         -- Send the post request to the server
end)

DataStore3.DeleteColumn(TableName, ColumnName)

  • arguments - TableName, ColumnName

TableName The name of the table where the column exists.
ColumnName The name of the column you want to delete.

  • Limitations

You can only delete 1 column at a time.

  • Example

Removes the column called gems from the table named userData

local DataStore3 = require(game:GetService("ServerScriptService").DataStore3Libary);  --Imports the DataStore3 libary

local Players = game:GetService("Players")

DataStore3.DeleteColumn("userData", "gems")

DataStore3.CreateColum(TableName, ColumnName, DataType)

  • arguments - TableName, ColumnName

TableName The table location you want the column to exist.
ColumnName The name of the column you want to create.
DataType The datatype of the column (find data types here).

  • Limitations

You can only create one column at a time.

  • Example

Creates a column called gems within the table called 'userData' with a INT(10) data type

local DataStore3 = require(game:GetService("ServerScriptService").DataStore3Libary);  --Imports the DataStore3 libary

local Players = game:GetService("Players")

DataStore3.CreateColumn("userData", "gems", "INT(10)")
Clone this wiki locally