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)