In a server module called "ServerNetwork" it has a constructor with a list of connections one of them being a event responder:

table.insert(self.connections, self._fireBullet.OnServerEvent:Connect(
	function(local_player, tool)
		global_tool:_fireBullet(tool);
	end
));

global_tool is a separate module and I am calling global_tool's constructor before all of this.

function _globalTool:_fireBullet(player, tool_name)
	if (self:_hasAuthority(tool_name)) then
		if (self._goodFireRate:InvokeClient(player)) then
			-- move bullet creation to :_createBullet()
			local bullet = bullets:FindFirstChild("Bullet"):Clone();
		end;
	end;
end;

Everything is all fine until it gets to the "self._goodFireRate" It says attempt to index a nil value, and I dont understand why. This is my constructor in global_tool.

local _globalTool = {}
_globalTool.__index = _globalTool;

function _globalTool.new(player)
	local self = setmetatable({
		connections = {},
		ammos = {};
	}, _globalTool);
	
	self._goodFireRate = shared_tools:FindFirstChild("GoodFireRate");
	
	return self;
end;

Thanks for reading

2 comments

0

IIRC if you want to use the self variable you have to use methods instead of functions, so globalTool.new would have to be redefined as globalTool:new

0

Its still erroring as nil