Connection Isn't Stopping

Hello, I’ve ran into a problem with my LocalScript.

So Ima be quick with this. When I press 1 or 2 to withdraw my weapon it works perfectly fine. But when I attempt to put my weapon back into his holster. I am still facing the way of my camera. Can somebody please help.

Codes:

-- Functions --
local function CameraMode()
	-- Check --
	Connection = RunService.RenderStepped:Connect(function(DeltaTime)
		-- Check --
		if Character['Humanoid'] and Character['HumanoidRootPart'] then
			Character['Humanoid'].AutoRotate = false
			local X,Y,Z = Camera.CFrame:ToOrientation()
			Character['HumanoidRootPart'].CFrame = Character['HumanoidRootPart'].CFrame:Lerp(CFrame.new(Character['HumanoidRootPart'].Position) * CFrame.Angles(0,Y,0),DeltaTime * 5 * 3)
		end
	end)
end
---
local function QuitMode()
	if Connection then
		Connection = nil
		Connection:Disconnect()
		Character['Humanoid'].AutoRotate = true
		Character['HumanoidRootPart'].CFrame = Character['HumanoidRootPart'].CFrame
	end
end
---

You are attempting to Disconnect() connection after you set it to nil already.

Even when I remove the Connection:Disconnect(). I still not getting out of the lock camera

“Connection” is just a variable that stands for a RBXScriptConnection setting it to nil won’t change the absolute connection object. Just disconnect it and then set it to nil if needed.

I meant that:

-- Functions --
local function CameraMode()
	-- Check --
	Connection = RunService.RenderStepped:Connect(function(DeltaTime)
		-- Check --
		if Character['Humanoid'] and Character['HumanoidRootPart'] then
			Character['Humanoid'].AutoRotate = false
			local X,Y,Z = Camera.CFrame:ToOrientation()
			Character['HumanoidRootPart'].CFrame = Character['HumanoidRootPart'].CFrame:Lerp(CFrame.new(Character['HumanoidRootPart'].Position) * CFrame.Angles(0,Y,0),DeltaTime * 5 * 3)
		end
	end)
end
---
local function QuitMode()
	if Connection then
		Connection:Disconnect()
                Connection = nil
		Character['Humanoid'].AutoRotate = true
		Character['HumanoidRootPart'].CFrame = Character['HumanoidRootPart'].CFrame
	end
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.