Can't :Disconnect() a renderstepped?

I want to disconnect an event, in this case RenderStepped, but it looks like it doesn’t work as the output still prints that it’s running even after using :Disconnect()

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local RSConnection
	
	char.ChildAdded:Connect(function(object)
		if string.match(object.Name, "Sword") then
			print("Connect")
			SwordEquipped = object
			RSConnection = RS.RenderStepped:Connect(SwordFunct)
		end
	end)
	
	char.ChildRemoved:Connect(function(object)
		if string.match(object.Name, "Sword") then
			print("Disconnect")
			RSConnection:Disconnect()
		end
	end)

Any ideas on how to fix this?

2 Likes

Does it print “Disconnect” or not

1 Like

It does print Disconnect, hmmm

1 Like

I dont see anything wrong with your code there, strange

1 Like

Can you be sure that only one char.ChildAdded:Connect(function(object)) is called followed be one char.ChildRemoved:Connect(function(object))? If the first is being called multiple times, RSConnection may be overwritten, leaving a connection live which you can’t disconnect.

If it’s possible this could be the case I’d store the connections as an array table.

1 Like

Oh, I did what you said and it works now.
I didn’t think about that solution, thank you so much!

2 Likes