How can i improve this code?

--!strict
local Inventory = {}

--// SERVICES
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
local Players = game:GetService('Players')
local LocalPlayer = Players.LocalPlayer

--// MODULES
local Modules = script.Parent.Parent
local Data = require(Modules.Data)

--// INSTANCES
local SlotsFolder = Workspace:FindFirstChild("Slots")
local Assets = ReplicatedStorage.Assets
local Events = Assets.Events
local Game = ReplicatedStorage.Game
local Ores = Game.Ores
local EquipOre = Events.Ore

--// UI
local Frames = Assets.Frames
local SlotTemplate = Frames.SlotTemplate
local ItemButton = Frames.ItemButton

--// VARIABLES
local clickedOre : string
local isSlotsLoaded = false
local pastButtons : {Instance} = {}

type OreData = {
	OreName : string,
	ColorName : Color3,
	Model : Model,
	Price : number,
	image : string
}
--// LOCAL FUNCTIONS
local function GetSlot(slotName: string) : Part
	local formattedName = slotName:sub(1, 4) .. "_" .. slotName:sub(5, 6)
	return SlotsFolder:FindFirstChild(formattedName) :: Part
end

local function GetOre(oreName: string) : Folder
	return Ores:FindFirstChild(oreName) :: Folder
end

local function ClearButtons(container : TextButton)
	for _, v in pairs(container:GetChildren()) do
		if v:IsA("TextButton") then
			v:Destroy()
			
			isSlotsLoaded = false
		end
	end
end

local function SlotAlreadyUsed(slotName: string, equippedOres)
	for _, equippedSlot in pairs(equippedOres) do
		if slotName == equippedSlot then
			return true
		end
	end
	
	return false
end

local function ResetCamera()
	local ActualCam = Workspace.CurrentCamera 
	if not ActualCam then return end
	
	ActualCam.CFrame = Workspace.CamPart.CFrame
end

local function LoadSlots(frame : Frame, isEquipped : boolean)
	local playerData = Data.GetData(LocalPlayer).Data
	if not playerData then return end

	local equippedOres = playerData.EquippedOres
	if isSlotsLoaded then return end
	
	local SlotDisplay = frame:WaitForChild('SlotDisplay') :: TextButton
	for i = 1, playerData.Slots do
		local newSlot = SlotTemplate:Clone()
		newSlot.Name = "Slot" .. i
		newSlot.Text = newSlot.Name
		newSlot.Parent = SlotDisplay
		isSlotsLoaded = true
		
		newSlot.MouseButton1Down:Connect(function()
			local currentCamera = Workspace.CurrentCamera
			local camPart = Workspace.CamPart
			if not (currentCamera and camPart) then return end

			Inventory.PlaceOre(clickedOre, newSlot.Name, isEquipped, equippedOres)
			ClearButtons(SlotDisplay)
			SlotDisplay.Visible = false
			
			if currentCamera.CFrame ~= camPart.CFrame then
				ResetCamera()
			end
		end)
	end
end

type EquippedOres = {[string] : string}
function Inventory.PlaceOre(oreName: string, slotName: string, isEquipped: boolean, equippedOres : EquippedOres, isLoading : boolean)
	local oreFolder = GetOre(oreName)
	if not oreFolder then return end

	local oreModule = oreFolder:WaitForChild('ModuleScript')
	local oreData = require(oreModule) :: OreData
	
	local workspaceSlot = GetSlot(slotName)
	if not workspaceSlot then return end

	if not isLoading and SlotAlreadyUsed(slotName, equippedOres) then
		return
	end
	
	local existingOre = Workspace:FindFirstChild(oreName) :: Model
	if isEquipped and existingOre then
		existingOre:PivotTo(workspaceSlot.CFrame + Vector3.new(0, 2, 0))
	else
		local clone : Model = oreData.Model:Clone()
		clone.Name = oreName
		clone.Parent = Workspace
		clone:PivotTo(workspaceSlot.CFrame + Vector3.new(0, 2, 0))
		
		local CloneHitBox = clone:WaitForChild('Hitbox') :: Part
		local ClickDetector = CloneHitBox:FindFirstChild('ClickDetector') :: ClickDetector
		ClickDetector.MouseClick:Connect(function(player)
			local camera = Workspace.CurrentCamera :: Camera
			local modelPivot = clone:GetPivot()
			
			camera.CFrame = CFrame.lookAt(modelPivot.Position + modelPivot.LookVector + Vector3.new(0,7,10), modelPivot.Position)
		end)
	end

	EquipOre:FireServer(oreName, slotName)
end

--// Carrega a interface do inventário
function Inventory.LoadInventory(frame : Frame, isOpening : boolean)
	local playerData = Data.GetData(LocalPlayer).Data
	if not (frame and playerData) then return end

	if isOpening then
		for _, oreName in pairs(playerData.UnlockedOres) do
			local oreFolder = GetOre(oreName)
			if not oreFolder then return end
			
			local oreModule = oreFolder:FindFirstChild('ModuleScript')
			local oreData = require(oreModule) :: OreData
			local button = ItemButton:Clone()
			local SubInventory = frame:FindFirstChild('SubInventory')
			
			button.Image = oreData.image
			button.ItemName.Text = oreData.OreName
			button.ItemName.TextColor3 = oreData.ColorName
			button.Parent = SubInventory

			button.MouseButton1Down:Connect(function()
				clickedOre = oreData.OreName
				local SlotDisplay = frame:FindFirstChild('SlotDisplay') :: Frame
				local isEquipped = playerData.EquippedOres[clickedOre] ~= nil
				
				LoadSlots(frame, isEquipped)
				SlotDisplay.Visible = true
			end)

			table.insert(pastButtons, button)
		end
	else
		for _, button in pairs(pastButtons) do
			button:Destroy()
		end
		table.clear(pastButtons)
	end
end

return Inventory

guys, I’m an intermediate programmer. I spent a long time without coding, and I made this module, what can I improve in this code?? I ended up adding this type checking just to learn more about it

Hello.

I have not found any artefacts: memory leaks, perfomance issues, but some code stylization standarts mistmaches. Here’s Roblox style guide, that based on Google style guide, but with Luau implementation.

I do not force you to strictly follow them, but you are going to need it if you want to work in team.

By the way on line 107 you annotated a type. I recommend you to annotate type only at the top of the code for better readability, because types are visible wherever they annotated.