PostAsync Datastore 2

Hi, how do I make the player’s coin amount data post using PostAsync? Here is my code:

local DataStore2 = require(game.ServerScriptService.DataStore2)

local defaultCashValue = 0

game.Players.PlayerAdded:Connect(function(plr)
	local coinsDataStore = DataStore2("Coins", plr)
	

	
	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	
	local function coinsUpdated(updatedValue)
		cash.Value = coinsDataStore:Get(updatedValue)
		game.ReplicatedStorage.UpdateClientCurrency:FireClient(plr, coinsDataStore:Get(defaultCashValue))
	end
	
	coinsUpdated(defaultCashValue)
	
	coinsDataStore:OnUpdate(coinsUpdated)
	
	
	
end)
databaseService = require(script.DatabaseService)
local ds = DataStore2:Get("Coins")
game.Players.PlayerAdded:connect(function(p)
	local num = ds:GetAsync(p.UserId)
	ds:PostAsync(num)
end)

Thank you!

PostAsync and DataStore2 are two different things. You seem to be using DataStoreService with DataStore2. You are grabbing player data with DataStoreService. This kind of defeats the purpose of using DataStore2. Can you elaborate on what you mean by using PostAsync? This is a method of HttpService…

1 Like

Sorry, I’m still learning Lua. What i am trying to do is take the data from DataStore2 and Use the PostAsync to send the data to a database.

Post doesn’t exist for DataStores. POST is an Http method: PostAsync is from HttpService that allows you to make a POST request from a Roblox game server. You should be using SetAsync for DataStores or Set for DataStore2.

That being said though, it looks like you aren’t using either DataStore2 nor DataStore properly. Did you salvage this code from another thread that you read? If you want to do that, then you should at least do some research to gain an understanding of how to use something.

1 Like

I’ve set up the Datastore2 to give me a value. If I use set, based on the documentation, it sets the value. In this case, it sets the value of coins the player has…? How would I use Set to send data to an external database?

The point of me doing this is so that I can view the player’s data. I just don’t know how to code that.

DataStore2 doesn’t have a PostAsync function, read above ^.

To save a value (override) using DataStore2, use:

   local DataStore2 = require(path.to.DataStore2)
   local Store = DataStore2("Coins", player)

   Store:Set(10) 
   -- or to increment instead, do 
   Store:Increment(10)

I know that. What I am asking is how can i send the amount of Coins the player has to a database so that I can see the amount from another website?

You can send Post requests to certain domains, send the data simply. DataStore2 and Post requests are entirely different topics, there was no need to refer to DataStore 2 for this.

databaseService = require(script.DatabaseService)

Assuming you already set your module up, require it with it’s name correctly later on and send a request.(?)

Something like this should be easy to incorporate (the asset itself).

Based on the guide, how would I call the “Coins” and send the amount the coins each player has to Trello? I’m still learning all of this, sorry if I seem annoying.

you’ll set up a Trello account, board, lists etc. then do as the tutorial says,

according to that tutorial, after you’ve got the value for ‘Coins’ for every player possibly through a generic loop, send each value to Trello using the module.

    local api = require(script.Parent.TrelloAPI)
    print("required module")

    local boardid = api:GetBoardID("Board Name here") 
    local listid = api:GetListID("List Name", boardid)  
 
    -- api.CardAdded(listid):Connect(cardAdded), you can set functions for these
	-- api.CardRemoved(listid):Connect(cardRemoved)
      
  for player, data in pairs(tab) do    
	     api:AddCard(player.Name, data, listid) -- name, desc, list id
         print("successfully sent!")   
   end

Would I replace data with “Coins”…?

Am I over thinking it? I think I am

You don’t want to use trello as a database, especially if what OP is doing what seems like is storing a currency which would be updated quite frequently. While it is possible, it is most definitely not ideal. Trello is for keeping track of tasks within software development.

@WooleyWool If you’re set on using DataStore2, this video will help you with exactly what you’re trying to do with storing player’s currency.

I watched that video. It already stores the player’s currency. I just need to know how to send that stored data to an external site, such as Trello, so that as a developer, I can view everyone’s currency.

That isn’t what you specified in the original post. But I must ask why would you want to do that? There is no real benefit to gain and if you really wanted to keep track of who has the most money, such as a leaderboard, you can use OrderedDataStores for that.

If you want to store data at an external location, you need a proper database system such as Firebase or MongoDB in which you will need to create your own REST API which you then use PostAsync to do a HTTP POST request to your API, in which your database would store. These are all things you can google to learn how to do yourself, however this will involve languages that aren’t roblox Lua (for the API) and seem to be a little out of your reach at the moment.

Again, Trello shouldn’t be used a database because it isn’t built to be a database. I personally suggest that making a system to view currency externally is not worth your time as there is little value this would add to your project.

I just want it for monitoring sales, amount of coins, etc. Do you know any good tutorials on Firebase or MongoDB with Roblox?

Monitoring sales/revenue sounds like analytics to me. Here is an analytics module for ROBLOX.

Regarding MongoDB or Firebase, you will need to branch out into other programming languages such as Node.js in which you will need to create your API. I’m unaware of any good tutorials for integrating it directly with ROBLOX. I personally don’t see any use cases for me where I’d need to be able to view a player’s currency outside of ROBLOX however.

Alrighty, I’m at the point where i’ll just take the analytics and skip the MongoDB or Firebase setup. It’s too stressful and seems very complicated to do. Thanks for the help :slight_smile:

where in my post does it say I’m doing that? I just gave Trello as an example website that you could update or sent data to.

especially if what OP is doing what seems like is storing a currency which would be updated quite frequently

The data does not necessarily have to be saved to an external source each time a value changes, you could just do this OnPlayerRemoving.

As it seems now the OP wanted to find a personal database, which was not obvious due to the usage of DataStore2 which saves data on it’s own, but if he wants to monitor revenue etc. then it is advised to take it as analytics rather than

player stats related data.