Hi, I am trying to initialize my framework but how I do it is very messy and would not work if i kept adding components. I need help trying to store the connections in a better way. Anything is helpful
local Framework = {}
Framework.__index = Framework
--[ Services ]--
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
--[ Modules ]--
local ExtraFunctions = require(ReplicatedStorage.Modules.Extra.ExtraFunctions)
local PlayerScripts = ExtraFunctions:WaitForChildWhichIsA(Players.LocalPlayer, "PlayerScripts") :: PlayerScripts
local PlayerModule = require(PlayerScripts:WaitForChild("PlayerModule")) :: any
local Controls = PlayerModule:GetControls()
function Framework.new()
local self = setmetatable({},Framework)
return self
end
function Framework:Initalize()
local Modules = script:GetChildren()
for _,Component in pairs(Modules) do
print("Initilized: "..Component.Name)
if Component.Name == "Viewmodel" then
local Module = require(Component)
local Viewmodel = Module.new()
Viewmodel:Equip()
local function Update(DeltaTime)
Viewmodel:Update(DeltaTime)
end
spawn(function()
RunService.RenderStepped:Connect(Update)
end)
end
if Component.Name == "Movement" then
local Module = require(Component)
Controls.moveFunction = Module.MoveFunction
end
end
end
return Framework