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()
pcall(function()
runService:UnbindFromRenderStep("updateViewmodel")
end)
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)
end
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)
self._model:SetPrimaryPartCFrame(modelPos+self._flicker*swayAngles)
self._flicker:Lerp(CFrame.new(0,0,0),self._recover*dT)
end
Upon trying to require this module and creating a new Viewmodel, the output starts spamming out these messages:
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!