local connection = nil
function someFunction()
if connection then connection:Disconnect() end
local part = Instance.new("Part")
RemoteEvent1:FireServer()
connection = RemoteEvent2.OnClientEvent:Connect(function()
part:Destroy()
end)
end
The issue here is, the someFunction() function is ran repeatedly at a fast rate, in which it will disconnect connection and replace it with a new one before the previous one finishes.
Hold on, why does the connection variable even exist? Why not leave the connection without a variable? Simple. To solve memory leak… I say.
But here I want to have the previous ones ending themselves instead of deleting them mid-run.
I’ve tried this, but the system doesn’t allow that:
function someFunction()
local part = Instance.new("Part")
RemoteEvent:FireServer()
local connection = RemoteEvent.OnClientEvent:Connect(function()
part:Destroy()
connection:Disconnect() -- Unknown global bbzbbbvz#*%#&@4
end)
end
Never learnt about RemoteFunctions… and I don’t think I can use it because there’s some complicated RemoteEvent chaining on the server-side… I’m not changing that.
I made some mistakes on the rewrote structure here, unsure if that changes stuffs. There are 2 different remotes:
local ProjectileFiring = remoteEvent1
local ProjectileDestroying = remoteEvent2
function someFunction()
if connection then connection:Disconnect() end
local part = Instance.new("Part")
ProjectileFiring:FireServer()
connection = ProjectileDestroying.OnClientEvent:Connect(function()
part:Destroy()
end)
end
I believe on the server side is ProjectileFiring.OnServerEvent, send a signal somewhere, and then that signal has it’s own .Event. And last, it’s ProjectileDestroying:FireClient() inside.
@CyberNinjaScripter I’m not sure how the client-server-client invoke will work like this, and I don’t see, or maybe just blind, about how that will solve the main issue.