clone.MouseButton1Down:Connect(function()) do --- makes a connection
clone:Destroy() ---- destroys the whole clone a while later, no disconnection beforehand
clone.MouseButton1Down:Connect(function()) do --- makes a connection
clone:Destroy() ---- destroys the whole clone a while later, no disconnection beforehand
Iām pretty sure that when an object is destroyed all connections attached to it disconnect automatically, to test this, after you destroy it you can print
print(type(clone)) (I meant to do this for the connection, find a way to initialize it outside of the function to debug that)
Btw not sure that will even work but worth a try, if itās type is rbxscriptconnection then Iām pretty sure it hasnāt disconnected
to test if its disconected u need to make local function
local test = clone.MouseButton1Down:Connect(function() end)
print(type(test)) -- should print function
clone:Destroy()
print(type(test)) -- if nil or error then its disconected
the code prints āuserdataā on both
then try
local test = clone.MouseButton1Down:Connect(function() end)
print(test)
clone:Destroy()
print(test)
the code prints āconnectionā on both
the connections are not cleared when destroying a part, but it does get disconnected, there is a read-only value called RBXScriptConnection.Connected
the right way to see if its connected would be this:
local test = clone.MouseButton1Down:Connect(function() end) --hold a reference to the connection
print(test.Connected) --true
clone:Destroy() --all connections connected to signal will be disconnected
print(test.Connected) --false
and yes, connections are disconnected when destroying instance.
That is what I tried to find. It will be helpful to know
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.