Help with self keyword

For some reason line 134 in the connect function is erroring I have 0 idea why as im new to using self keyword

-- Do not Remove this
-- Operator Created by Carrotoplia
-- Opensource Free Signal maker.
-- Devforum Post
-- https://devforum.roblox.com/t/a/1990129

-------------------------TODO---------------------------
-- Setup SubscribeAsync

local Module = {}
Module.Signals = {} -- Stores every signal well ever.
Module.SignalID = {} -- Stores signals in a dictionary with an ID
Module.OnSignalConnections = {} -- Stores Connections that are fired opon any signal fired provided it accepts it.

local Remote = Instance.new("RemoteEvent", script)
local IsClient = game["Run Service"]:IsClient()


------------------------------------- CROSS SERVER MESSAGER ---------------------------------------------
Module.Sharing = {} -- Stores all data needed to be sent
if not IsClient and false then -- SET TO FALSE TO MAKE IT NOT DO IT IN STUDIO
	-- It is running on the server
	local MessageService = game:GetService("MessagingService")
	MessageService:SubscribeAsync("OperatorSignal", function(tab)
		for _,Data in pairs(tab) do
			if Module.SignalID[Data.ID] then
				Data.Source = ""
				Module.SignalID[Data.ID]:Fire(Data)
			end
		end
	end)
	while true do wait(5)
		if #Module.Sharing >= 1 then
			local Result,Warning = pcall(function()
				MessageService:PublishAsync("OperatorSignal", Module.Sharing)
			end)
			if not Result then warn(Warning) else
				Module.Sharing = {}
			end
		end
	end
end

------------------------------------ Signal Replicator -------------------------------------------
if IsClient then
	Remote.OnClientEvent:Connect(function(ID, data)
		if Module.SignalID[ID] ~= nil then
			data.Replicated = true
			data.Source = "Server"
			Module.SignalID[ID]:Fire(data)
		end
	end)
else
	Remote.OnServerEvent:Connect(function(Player, ID, data)
		if Module.SignalID[ID] ~= nil then
			data.Replicated = true
			data.Source = Player
			Module.SignalID[ID]:Fire(data)
		end
	end)
end

function Module:New(ID, IsReplicated, IsGamewide)
	local Meta = {}
	local Signal = setmetatable({}, Meta)
	Signal.Module = Module
	Signal.__type = "Signal"
	Signal.IsReplicated = IsReplicated
	Signal.IsGamewide = IsGamewide
	Signal.ID = ID
	Signal.UUID = game:GetService("HttpService"):GenerateGUID(false)
	Signal.Connections = {}

	function Signal:Fire(t, ...)

		-- Checks if it is already fired from gamewide so it does not create a message loop overloading it.
		local IsGameSignal = t.IsGameSignal
		if IsGameSignal == nil then IsGameSignal = false end

		IsClient = game["Run Service"]:IsClient()
		for _,Connection in pairs(self.Connections) do
			Connection.Function("local", ...)
		end
		for _,Connection in pairs(self.Module.OnShoutConnections) do
			Connection.Function("local", ...)
		end
		if self.IsReplicated then
			-- You wouldnt be able to get a replicated signal if it wasn't using an ID so it warns
			if not self.ID then
				error("SignalID is required for Replicated signals Consider toggling off Replicated (signal.IsReplicated)")
			end
			if IsClient then
				Remote:FireServer({...})
			else
				-- Table so you can send it to multiple clients if you desire
				if typeof(Signal.IsReplicated) == "table" then
					for _,plr in pairs(Signal.IsReplicated) do
						Remote:FireClient(plr, self.ID, {...})
					end
				elseif typeof(Signal.IsReplicated) == "Instance" then
					Remote:FireClient(Signal.IsReplicated, self.ID, {...})
				else
					Remote:FireAllClients(self.ID, {...})
				end
			end
		end
		if self.IsGamewide and not IsClient and not IsGameSignal then
			if not Signal.ID then
				error("SignalID is required for Gamewide signals Consider toggling off Gamewide (signal.IsGamewide)")
			end
			local data = {}
			data.ID = self.ID
			data.Data = ...
			table.insert(Module.Sharing, data)
		end
	end

	function Signal:Connect(f)
		local Connection = {}
		Connection.Module = Module
		Connection.Signal = Signal
		Connection.Function = f
		Connection.__type = "Connection"
		Connection.UUID = game:GetService("HttpService"):GenerateGUID(false)
		Connection.AcceptsReplicated = true
		Connection.AcceptsGamewide = true

		function Connection:Disconnect()
			Connection.Signal.Connections[Connection.UUID] = nil
		end
		function Connection:Reconnect()
			Connection.Signal.Connections[Connection.UUID] = Connection
		end
		table.insert(self.Connections, Connection)
		return Connection
	end

	function Signal:ClearConenctions()
		Signal.Connections = {}
	end

	function Signal:Wait(...)
		local running = coroutine.running()
		local param = ...
		task.spawn(function()
			local Connection = Signal:Connect(function(...)
				if param ~= nil and param == ... then
					coroutine.resume(running)
				elseif param == nil then
					coroutine.resume(running)
				end
			end)
		end)

		coroutine.yield()
	end
	if Signal.ID then
		self.Module.SignalID[self.ID] = Signal
	end

	function Meta:__newindex(index,value)
		if index == "ID" or index == "IsReplicated" or index == "IsGamewide" then
			rawset(self, index, value)
			if index == "ID" then
				self.Module.SignalID[value] = self
				self.Module.SignalID[self.ID] = nil
			end
		else
			error("Attempted to set Signal with non accepted option " .. index .. "'.")
		end
	end

	table.insert(Module.Signals, Signal)
	return Signal
end

function Module:GetSignal(ID, IsReplicated, IsGamewide)
	if not ID then error("ID is nil or false. Getsignal") end
	if not Module.SignalID[ID] then
		local Signal = Module.New(ID, IsReplicated, IsGamewide)
		return Signal
	else
		return Module.SignalID[ID]
	end
end

function Module.OnSignal(config, f)
	local Connection = {}
	Connection.Module = Module -- Creation so It does not create new functions per 
	Connection.__type = "Connection"
	Connection.ID = game:GetService("HttpService"):GenerateGUID(true) -- Creates a ID for the connection 
	Connection.Function = f
	Connection.OldFunction = f
	Connection.AcceptsReplicated = false
	Connection.AcceptsGamewide = false
	if config ~= nil and config.AcceptsReplicated then
		Connection.IsNonReplicated = true
	end
	if config ~= nil and config.AcceptsGamewide then
		Connection.AcceptsGamewide = true
	end

	-- Used to destroy connections
	function Connection:Disconnect()
		self.Module.OnSignalConnections[Connection.ID] = nil
	end

	function Connection:Reconnect()
		Module.OnSignalConnections[Connection.ID] = Connection
	end


	Module.OnSignalConnections[Connection.ID] = Connection
	return Connection
end


return Module
1 Like

What does the error say?

30charlimit

1 Like

1 Like

And this code produces it

local Operator = require(game.ReplicatedStorage["Operator 2.1"])

local Signal = Operator:New()

Signal.Connect({}, function(Source, Data)

print(Source .. "/" .. Data)

end)

Signal:Fire("SignalA")
1 Like

You’re supposed to do Signal:Connect, also remove {}:

Signal:Connect(function(Source, Data)
1 Like

Ah i forgot about that
30charactrs