I have an ability framework and recently I wanted to add new functionality to projectiles, within my framework I handle projectile hits by creating a connection on a remote event like so:
local con
con = ProjectileHit.OnServerEvent:Connect(function(hitplayer,projectileability,hitpos,hitPart,hitHumanoids,offset,id)
if hitplayer == player and ability == projectileability and projectileNumber == id then
con:Disconnect()
print("disconnected")
--Projectile hit code
end
end)
I was trying to add projectiles that can go through and hit multiple targets, while doing this I noticed that firing the remote event multiple times for each target hit would cause the error ," attempt to index nil with ‘Disconnect’ ". I’m not really sure why this happens since surely the connection’s been made if the code can error, so it just made no sense to me how the connection could be nil.
The first time I shoot a projectile, this doesn’t happen, only after that.