Connection is nil

I’m using connection in order to stop them from firing continously, but doing :Disconnect() just leads to “attempt to index nil with Disconnect”. These are inside an event as well, so that’s why I’m trying to disconnect them.

I’m not sure why the connections is defining as nil even if I already connected to a function. the functions also works fine too. anyone have a solution or perhaps another solution to this? thanks!

	shootConnection = signal:OnEvent("Shoot", function(plr, direction)
		weapon:Shoot(direction)
	end) print(shootConnection)

	reloadConnection = signal:OnEvent("Reload", function(plr)
		weapon:Reload()
	end) print(reloadConnection)

	unequipConnection = signal:OnEvent("Unequip", function(plr)
		shootConnection:Disconnect() 
		reloadConnection:Disconnect() 
		unequipConnection:Disconnect()

		weapon = nil
	end)

image

I’m not sure what signal:OnEvent is. Is it some sort of module you are using?
In any case, it is not returning an event that you can call :Disconnect() on.
If you provide more information regarding the signal, I may be able to help you more.

Generally, if you’re trying to connect an event, that’ll have a . instead of :

shootConnection = signal.OnEvent("Shoot",function(plr, dir)
  weapon:Shoot(dir)
end)

yes, it’s a module I use to handle remote events.

this does not work since the module I use requires :OnEvent(). should I just use a regular remote event?

You’re using Roblox’ normal disconnect, though. So you’re trying to disconnect something which you never connected, because it’s not using Roblox’ connectors

Make sure the :OnEvent() callback function returns an RBXScriptConnection object.

can you show the module? the module probably doesn’t return a connection with the Disconnect() function and the Connected property.

i don’t see any reason to use a self-made RBXScriptSignal instead of using RemoteEvents or BindableEvents