DataStore saves your data on the server globally.
DataStore2 however saves everything in a table.
If you require any help regarding DataStore2, make sure to read this post: Click here
From Kampfkaren, this is how a example code can look for DataStore2. Credits to him.
01 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
02 | local Players = game:GetService( "Players" ) |
03 | local ServerScriptService = game:GetService( "ServerScriptService" ) |
05 | local DataStore 2 = require(ServerScriptService.DataStore 2 ) |
08 | DataStore 2. Combine( "DATA" , "coins" ) |
10 | Players.PlayerAdded:Connect( function (player) |
11 | local coinStore = DataStore 2 ( "coins" , player) |
13 | local function callRemote(value) |
14 | ReplicatedStorage.CoinAmount:FireClient(player, value) |
19 | callRemote(coinStore:Get( 100 )) |
22 | coinStore:OnUpdate(callRemote) |
26 | local Products = require(ReplicatedStorage.Products) |
28 | ReplicatedStorage.BuyProduct.OnServerEvent:connect( function (player, productName) |
29 | if not Products [ productName ] then return end |
31 | local coinStore = DataStore 2 ( "coins" , player) |
32 | local productPrice = Products [ productName ] .price |
34 | if coinStore:Get( 100 ) > = productPrice then |
35 | print ( "Buying product" , productName) |
36 | coinStore:Increment(-productPrice) |
Happy Programming! Comment if you have any concerns.