Camera moving freely on doubletask

Edit: This post has now been solved!

-- Camera part
Mouse.Button2Down:Connect(function()
	if IsBuilding.Value == true then
		MouseMove = Mouse.Move:Connect(function()
			UIS.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
			CameraAngle = UIS:GetMouseDelta().X/4700
		end)
		Mouse.Button2Up:Connect(function()
			CameraAngle = 0
			MouseMove:Disconnect()
			UIS.MouseBehavior = Enum.MouseBehavior.Default
		end)
	end
end)

Here’s the issue, you’re nesting event connections without appropriately disconnecting said event connections. This means that each time the “.Button2Down” event is firing on the mouse you’re potentially creating a new connection to the mouse’s “.Button2Up” event.

-- Camera part
Mouse.Button2Down:Connect(function()
	if IsBuilding.Value == true then
		MouseMove = Mouse.Move:Connect(function()
			UIS.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
			CameraAngle = UIS:GetMouseDelta().X/4700
		end)
		local Connection
		Connection = Mouse.Button2Up:Connect(function()
			CameraAngle = 0
			MouseMove:Disconnect()
			UIS.MouseBehavior = Enum.MouseBehavior.Default
			Connection:Disconnect()
		end)
	end
end)

That seems to be a fix to a bug in the code, which I appreciate, but unfortunately the same bug is still happening.

Okay, so the camera’s CFrame destination is only being calculated when a key is first pressed, this needs to be done inside the RenderStepped loop.

UIS.InputBegan:Connect(function(Input, Gameproccessed) 
	if not Gameproccessed and IsBuilding.Value == true then
		if Input.KeyCode == Enum.KeyCode.W and WPressed == false or Input.KeyCode == Enum.KeyCode.Up and WPressed == false then
			WPressed = true
		elseif Input.KeyCode == Enum.KeyCode.A  and APressed == false or Input.KeyCode == Enum.KeyCode.Left and APressed == false then
			APressed = true
		elseif Input.KeyCode == Enum.KeyCode.S and SPressed == false or Input.KeyCode == Enum.KeyCode.Down and SPressed == false then
			SPressed = true
		elseif Input.KeyCode == Enum.KeyCode.D and DPressed == false or Input.KeyCode == Enum.KeyCode.Right and DPressed == false  then
			DPressed = true
		end
	end
end)

Run.RenderStepped:Connect(function()
	if WPressed then
		--Do code.
	elseif APressed then
		--Do code.
	elseif SPressed then
		--Do code.
	elseif DPressed then
		--Do code.
	end
end)

Edit: The post has been completed, thanks!

Edit: The post has been fixed thanks!