Help with Module Script

Hello everyone! I’m making right now Gun Framework, but, I stopped developing it only because of one problem. So, I have a “new” function that sets up all variables in self, and then when player is loaded, it should load a viewmodel with all changed self variables. But, they aren’t changing! I don’t know how to fix it, I literally can’t do anything.

Here is part of Viewmodel:

function framework.new()
		local self = setmetatable({}, framework)
		self.Name = "Untitled"
		self.Equipped = false
		self.Firing = false
		self.Reloading = false
		self.Inspecting = false
		self.Walking = false
		
		self.ADS = false
		self.PointAim = false
		_G.RunViewmodel = false
		_G.CanRun = true
		self.CanAimLocal = true
		
		-- Input
		self.ReloadExecute = false
		self.Debounce = 0.2
		
		-- Ammo
		self.MaxAmmo = 30
		self.Ammo = self.MaxAmmo
		
		-- Bullets
		self.Bullets = {}
		self.BulletSpeed = 0
		self.BulletMass = 0
		self.BulletSize = 0
		self.BulletDrag = 0
		
		-- Springs
		self.Springs = {}
		self.Springs.Recoil = Modules.Spring.create()
		self.Springs.RecoilRotation = Modules.Spring.create()
		self.Springs.RecoilCamera = Modules.Spring.create()
		self.Springs.Sway = Modules.Spring.create()
		
		-- Alphas
		self.Alphas = {}
		self.Alphas.Aim = 0
		self.Alphas.PointAim = 0
		self.Alphas.Equip = 0
		self.Alphas.Run = 0
		self.Alphas.Obstruct = 0
		
		-- Recoil
		self.RecoilPatternX = Vector2.new()
		self.RecoilPatternY = Vector2.new()
		self.RecoilPatternZ = Vector2.new()
		self.Random = Random.new()
		
		-- CFrames
		self.OldCameraCF = CFrame.new()
		self.LastCameraCF = CFrame.new()
		self.BobCameraCF = CFrame.new()
		self.AimCFrame = CFrame.new()
		self.RotViewmodel = CFrame.new()
		self.SprintCF = CFrame.new()
		self.ShakeCF = nil
		
		-- Animations
		self.FireAnim = nil
		self.EmptyFireAnim = nil
		self.DeadTriggerAnim = nil
		self.InspectAnim = nil
		self.EquipAnim = nil
		self.UnequipAnim = nil
		self.ReloadAnim = nil
		self.EmptyReloadAnim = nil
		self.IdleAnim = nil
		self.EmptyIdleAnim = nil
		self.WalkAnim = nil
		self.RunAnim = nil
		
		-- Main
		self.RPM = 0
		self.RPM_t = 60 / self.RPM
		self.MaxWeight = 0
		self.Weight = self.MaxWeight
		_G.ServerWeight = self.Weight
		self.GlobalDivider = 1
		self.NextShot = 0
		self.Overheat = 0
		self.Turn = 0
		
		-- CurrentMode = fire mode in number
		-- CurrentStringMode = fire mode in string
		self.CurrentMode = 2
		self.CurrentStringMode = nil
		self.MagLoaded = false
		self.IsChambered = false
	
		self.Viewmodel = nil
		self.RootPart = nil
		self.FakeCamera = nil
		
		self.UI = nil
		self.Sounds = nil
		self.Module = nil
		self.Camera = nil
		self.Mouse = nil
		self.Assets = nil
		
		self.Debugging = false
		return self
	end
	
	function framework:Load(name)
		for i, v in pairs(workspace.Camera:GetChildren()) do
			if v:IsA("Model") then
				v.Unequip:Play()
				task.wait(v.Unequip.Length)
				v:Destroy()
			end
		end
		if not self.Equipped then 
			self.Equipped = true
			equipped = name 
		else return false end
		local tostr = tostring(name)
		local guns = script.Parent:FindFirstChild("Guns")
		if not guns then return end
		
		local viewmodel = guns[tostr].Viewmodel
		if not viewmodel then return end
		
		local sounds = guns[tostr].Sounds
		if not sounds then return end
		self.Sounds = sounds
		
		local module = require(guns[tostr].Settings)
		if not module then return end
		self.Module = module
		
		local Data = module["Data"]
		if not Data then return end

                self.Camera = workspace.CurrentCamera
		self.Mouse = Player:GetMouse()
		self.Assets = script.Parent["Assets"]

		self.UI = Player:WaitForChild("PlayerGui")
		self.Viewmodel = viewmodel:Clone()
		self.Viewmodel.Parent = self.Camera
		self.RootPart = self.Viewmodel["RootPart"]
		self.CurrentStringMode = Data["FireMode"].Modes[self.CurrentMode]

		local FakeCamera = self.RootPart["root"].torso.spine1.spine2.spine3.spine4.spine5.neck["fakecam"]
		self.FakeCamera = FakeCamera
		self.Camera.FieldOfView = require(ReplicatedStorage.Common.Configuration.Local).fieldOfView

                self.Name = self.DeleteSpaces(Data["OriginalName"])
		self.MaxAmmo = Data["MaxAmmo"]
		self.MaxWeight = Data["Weight"]
		self.CurrentMode = Data["FireMode"].Current

		local settings = Data.Settings
		if not settings then return end
		self.BulletSpeed = settings.BulletSpeed
		self.BulletMass = settings.BulletMass
		self.BulletSize = settings.BulletSize
		self.BulletDrag = settings.BulletDrag

		self.RecoilPatternX = settings.RecoilPatternX
		self.RecoilPatternY = settings.RecoilPatternY
		self.RecoilPatternZ = settings.RecoilPatternZ

		self.Debounce = settings.Debounce
		self.MagLoaded = settings.MagLoaded
		self.IsChambered = settings.IsChambered
				
		local CurrentMode = Data["FireMode"].Current
		local ModeString = Data["FireMode"].Modes[tonumber(CurrentMode)]
				
	        local Info = self.UI:WaitForChild("Manager")["Info"].Frame
		if not Info then return end
		Info["Mode"].Text = self.SpaceOut(ModeString)
		Info["Weapon"].Text = Data["OriginalName"]

-- continue of the code, I don't want to paste here full code

I don’t have any errors in output, I don’t know what to do.
If someone can help me, that would be really appreciated! Thanks.

1 Like

If this is meant to be like an OOP system then your not really meant to put the functions inside of it as generally the “new” function creates the metatable then you have the other functions outside of that just inside the module script.

1 Like

Place functions outside the framework.new() function.

1 Like

Ensure your framework.new() function is correctly invoked and that the player’s viewmodel setup occurs after this initialization. Check the sequence in which these functions are called and confirm that variables modified in the framework:Load(name) method are properly applied to the instance created by framework.new(). This might involve debugging to verify that the Load method is called on the correct framework instance and that the instance’s properties are updated as expected before they are used. Also, consider adding print statements or breakpoints in your development environment

1 Like

it is outside. I don’t think that’s the problem

1 Like