Is this datastore script correct?

Im just trying to use datastore2 and im wondering if this script is correct

local ArmorModule = require(game.ReplicatedStorage:WaitForChild("ArmorHandler"))
local newArmor = ArmorModule.chooseRandom():Clone()
local Armor = newArmor

local function LoadData()

	local template = game.StarterGui.MainGui.InventoryHolder.Inventory.Templates.Template
	local newTemplate = template:Clone()
	local ArmorName = ArmorModule.armors.Name
	local ArmorModule = ArmorModule.chosenArmor
	local Viewport = game.StarterGui.MainGui.InventoryHolder.Inventory.Templates.Template.VP
	local OldArmor = Viewport:FindFirstChild("Model")

	local plr = game.Players.LocalPlayer
	local empty = ArmorName == ""
	local char = plr.Character or plr.ChildAdded:Wait() 

	if newTemplate.ArmorName.Value ~= ArmorName then
		newTemplate.ArmorName.Value = newTemplate:WaitForChild("ArmorName").Value
	end

	if OldArmor then
		OldArmor:Destroy()
	end

	if not empty then
		Armor = Armor:Clone()
		Armor:SetPrimaryPartCFrame(CFrame.fromOrientation(0, 45, 0))
		Armor.Parent = newTemplate.VP
	end
end

local function UpdateInventory()
	for i, data in pairs(game.StarterGui.MainGui.InventoryHolder.Inventory.Duplicates:GetChildren()) do
		LoadData(
			game.StarterGui.MainGui.InventoryHolder.Inventory.Duplicates:GetChildren()[i]
		)
	end
end

game.ReplicatedStorage.Events.DataUpdater.OnServerEvent:Connect(function(player)
	local InventoryStore = datastore2("Inventory", player)
	UpdateInventory()
	InventoryStore:Update()
	
end)

It’s wrong when you want to update the datastore. It requires an argument, which is a function that returns the new data to set.
https://kampfkarren.github.io/Roblox/api/#datastoreupdate

1 Like

Have you tested it out?

Then you would know.

I just wanted to make sure before testing

1 Like

I would say test 1st.

You never know it might just work