I’ve just coded this and I wanted to know if there was a better way to update the player’s data (which is a dictionary) without using :Set(). Some friends have told me I shouldn’t use :Set() for updating data when using DataStore2 but I don’t see any functions in the DataStore2 module that could work for me other than :Set().
Yes I know this method to change the player’s cash is stupid and I shouldn’t use it when I officially publish my game.
Method for changing the player’s cash:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Settings = require(ReplicatedStorage.Modules.Settings)
ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player, Amount)
local PlayerDataStore = DataStore2("PlayerData", Player)
local function GetDefaultData()
return Settings.Stats
end
local DefaultData = GetDefaultData()
local Data = PlayerDataStore:Get(DefaultData)
Data.Money = Amount
PlayerDataStore:Set(Data)
end)
Settings module:
local Settings = {}
Settings.Stats = {
Money = 200,
Level = 0,
MaxLevel = 100,
XP = 0,
MaxXP = 5000
}
return Settings