Disconnecting half works?

So, I’m trying to disconnect an event, then reconnect it so that it doesn’t stack events weirdly, it does so, but still activates once after I disconnect it? It’s causing so many issues, does anyone know what causes it?

GiveGun.Event:Connect(function(GunModel)
	local AnimationsFolder = RepStore:WaitForChild(GunModel.."Animations")
	GunModel = RepStore:WaitForChild(GunModel):Clone()
	TrueModel = game.Workspace.Camera:FindFirstChild("Viewmodel")
	if TrueModel:FindFirstChildWhichIsA("Model") then
		TrueModel:FindFirstChildWhichIsA("Model"):Destroy() 
	end
	wait(.0001)
	MainModule.weldgun(GunModel)
	MainModule.animate(TrueModel, AnimationsFolder.Hold)
	print("e")
	print(GunModel.Name.." "..TrueModel.Name)
	TrueModel.Parent = game.Workspace.Camera
	MainModule.equip(TrueModel, GunModel)
	MainModule.animate(TrueModel, AnimationsFolder.Hold)
	local CanFire = true
	if GunModel.Name == "StarterPistol" then
		Delayy = 0.5
		Range = 50
	elseif GunModel.Name == "LaserRifle" then
		Delayy = 0.25
		Range = 100
	end
	pcall(function()
		print(Clickdet.Connected)
		if Clickdet.Connected then
			Clickdet:Disconnect()
		end
		print(Clickdet.Connected)
	end)
	Clickdet = game:GetService("RunService").RenderStepped:Connect(function(dt)
		mouse.Button1Down:Connect(function()
			if CanFire then
				CanFire = false
				recSpring:shove(Vector3.new(3, 0, 0))
				print(GunModel.Name)
				MainModule.cast(GunModel.Components.Barrel.Position, GunModel.Name, mouse.Hit.Position,Range)
				wait(Delayy)
				CanFire = true
			end
		end)
	end)
end)

i dont know if i’ve seen worse or what

1 Like

This a really stupid piece of code. Creating a Button1Down connection each renderstepped and not disconnecting it?

2 Likes

i have taken a pretty big break from scripting but correct me if i’m wrong, but isn’t wait’s minimum time 0.03?

1 Like

While I had a hard time trying to understand your code, the disconnect function is indeed working fine, but since there are multiple connections of the Button1Down function, all of them would still run every time you click your left mouse button.

Note that the RenderStepped function is not required in your case at all.

1 Like

Why are you connecting to Button1Down every frame? Why are you doing wait(0.0001) even though wait can only wait a minimum of 0.03 seconds? Why aren’t you using task.wait? I have so many questions about this code.

Connections don’t need to be connected every frame to work, I don’t know where people are getting that idea, since it’s counterintuitive to what connections are meant to do FOR you.

1 Like