RBXScriptConnection not disconnecting

Trying to disconnect a RBXScriptConnection but it doesn’t disconnect despite it not giving off any errors as it’s inside of a pcall function.

I also made it print the type to make sure it’s a RBXScriptConnection and it is but still the Mouse.Move function never works.

Also the position changed isn’t working either; it’s supposed to make the highlight vanish if the Player walks away from the Target and the Magnitude of their PrimaryPart positions is above 30 but that doesn’t work either.

Any tips on how to fix this at all?

Put the disconnect inside the if statement
image

And the same for the previous one
image

I tried that and it still didn’t work.

can you try

if Mouse_Moved.Connected then
    Mouse_Moved:Disconnect()
    print(`Type: {typeof(Mouse_Moved)}`)
end

…and the same for the other one?

Remove the pcall function u dont need that actually

Alright I’ll screenshot the output for that as well

Okay so just take the pcall function out and do you think it’d work?

Try it out,i am not really sure because sometimes it might work and i dont really think pcall is necessary

And pcall is the reason why it printed twice because the first time didnt work

1 Like

It still doesn’t disconnect.

The code;

-- > Mouse Moved:
							
							if Mouse_Moved.Connected then

								print(`Type: {typeof(Mouse_Moved)}`)
								
								Mouse_Moved:Disconnect()
								
								print(`Type: {typeof(Mouse_Moved)}`)
								
							end
							
							-- > Position Changed:
							
							if CFrame_Changed.Connected then
								
								print(`Type: {typeof(CFrame_Changed)}`)
								
								CFrame_Changed:Disconnect()
								
								print(`Type: {typeof(CFrame_Changed)}`)
								
							end

Images;

image

image

image

I guesss put a debounce in it cause i think the mouse movement might be the problem,i think when u move right,the thing will detect it twice,so the best will be to use debounce.

THIS ALSO HAPPENS TO MINE TOO.

i fixed it by disconnecting after the i call the function

How would the debounce be added in this situation

this might be unrelated to the disconnect not working but you cant use Changed events on physics, such as CFrame. You would need to loop the function in a while true loop or use RunService.Heartbeat

1 Like