I need help with my custom Viewmodel class

So, I made a module script that basically mimics a custom class behavior, sorta.
This is meant to be a viewmodel framework of mine:

function Viewmodel.new()
    runService:BindToRenderStep("updateViewmodel",Enum.RenderPriority.Camera.Value - 1, Viewmodel._updateView)
    return setmetatable(
            _model = game.ReplicatedStorage:WaitForChild("Dischargable Pistol"):Clone();    
            _offset = Vector3.new(0,0,0);
            _recover = 0.05;
            _camera = workspace.CurrentCamera;
            _angular = 0.1;
            _flicker = CFrame.new(0,0,0);
            _sway = 0.05;
    }, Viewmodel)

    function Viewmodel:_updateView(dT)
        if self._model == nil then return end
        if self._camera == nil then return end
        if elf._model.PrimaryPart == nil then return end
        local mouseDelta = inputService:GetMouseDelta()
        local xDiff = mouseDelta.X
        local yDiff = mouseDelta.Y
        local modelPos = self._model.PrimaryPart.CFrame:Lerp(self._camera.CFrame + self._offset,self._sway*dT)
        local swayAngles = CFrame.Angles(math.rad(xDiff*self._angular),math.rad(yDiff*self._angular),0)

Upon trying to require this module and creating a new Viewmodel, the output starts spamming out these messages: unknown

Line 103 is this line: if self._model == nil then return end

The error seems to occur not only with _model, but with all the other metatable values, too.

I have spent more than 2 hours tweaking and interchanging things and nothing seemed to work. Any help would be greatly appreciated, keep in mind that I am not really familiar with metatables so I might not understand certain aspects, so it would be better if you could explain everything more in-depth. Thanks in advance!

1 Like

Send the line of code where you call _updateView function, and check if you’re doing the OOP implementation correctly in Lua just in case but I’d have to bet you given a number value somehow incorrectly.

I think your dT argument (delta time I am assuming) is being seen as replacement of self somehow?

Oh god. I will check if deltaTime replaces self right now, to be honest, im not even sure if I can listen to DeltaTime using BindToRenderStep.