Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.
Reece Harris edited this page Jul 10, 2021 · 3 revisions

DataStore3.testConnection()

  • Example

Allows you to test your server / credentials status

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

DataStore3.testConnection()

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.CreateColumn(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)")

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.CreateTable(TableName, PrimaryKey, DataType)

  • arguments - TableName, PrimaryKey, DataType

TableName The table you want to create.
PrimaryKey The name of the primary key.
DataType The data type of the primary key.

  • Limitations

You can only create 1 table and only specify 1 column (Primary key)

  • 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.DeleteTable("userData")

DataStore3.DeleteTable(TableName)

  • arguments - TableName

TableName The table you want to delete.

  • Limitations

You can only delete one table 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.DeleteTable("userData")